CF1182F.Maximum Sine

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have given integers aa , bb , pp , and qq . Let f(x)=abs(sin(pqπx))f(x) = \text{abs}(\text{sin}(\frac{p}{q} \pi x)) .

Find minimum possible integer xx that maximizes f(x)f(x) where axba \le x \le b .

输入格式

Each test contains multiple test cases.

The first line contains the number of test cases tt ( 1t1001 \le t \le 100 ) — the number of test cases.

The first line of each test case contains four integers aa , bb , pp , and qq ( 0ab1090 \le a \le b \le 10^{9} , 1p1 \le p , q109q \le 10^{9} ).

输出格式

Print the minimum possible integer xx 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)=0f(0) = 0 , f(1)=f(2)0.866f(1) = f(2) \approx 0.866 , f(3)=0f(3) = 0 .

In the second test case, f(55)0.999969f(55) \approx 0.999969 , which is the largest among all possible values.

首页