CF1182F.Maximum Sine

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

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 a≤x≤ba \le x \le b.

已知整数 aa、bb、pp 和 qq。令 f(x)=abs(sin(pqπx))f(x) = \text{abs}(\text{sin}(\frac{p}{q} \pi x))。

在满足 a≤x≤ba \le x \le b 的整数 xx 中,求使 f(x)f(x) 取得最大值的最小可能整数 xx。

输入格式

Each test contains multiple test cases.

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

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

每个测试包含多个测试用例。

第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)——即测试用例的个数。

每个测试用例的第一行包含四个整数 aa、bb、pp 和 qq(0≤a≤b≤1090 \le a \le b \le 10^{9},1≤p,q≤1091 \le p, q \le 10^{9})。

输出格式

Print the minimum possible integer xx for each test cases, separated by newline.

对每个测试用例,输出可能的最小整数 xx,各结果之间用换行符分隔。

输入输出样例

  • 输入#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.

在第一个测试用例中,f(0)=0f(0) = 0,f(1)=f(2)≈0.866f(1) = f(2) \approx 0.866,f(3)=0f(3) = 0。

在第二个测试用例中,f(55)≈0.999969f(55) \approx 0.999969,是所有可能取值中的最大值。

输入解题思路,AI测评打分。不知道怎么写?

首页