CF1182F.Maximum Sine
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have given integers a , b , p , and q . Let f(x)=abs(sin(qpπx)) .
Find minimum possible integer x that maximizes f(x) where a≤x≤b .
输入格式
Each test contains multiple test cases.
The first line contains the number of test cases t ( 1≤t≤100 ) — the number of test cases.
The first line of each test case contains four integers a , b , p , and q ( 0≤a≤b≤109 , 1≤p , q≤109 ).
输出格式
Print the minimum possible integer x for each test cases, separated by newline.
输入输出样例
输入#1
2 0 3 1 3 17 86 389 995
输出#1
1 55
说明/提示
In the first test case, f(0)=0 , f(1)=f(2)≈0.866 , f(3)=0 .
In the second test case, f(55)≈0.999969 , which is the largest among all possible values.