题面
You have a prize wheel divided into sections, numbered from to . The sections are arranged in a circle, so after section , the numbering continues again from section .
Initially, the prize pointer is at section . Each time you spin the wheel, the pointer moves exactly sections forward. That is, after one spin, the pointer moves from section to section , after two spins to , and so on .
You may spin the wheel any number of times (including zero). After you stop, the section where the pointer finally lands determines your prize: you receive an amount equal to the number of that section.
What is the maximum prize you can obtain?
Here, denotes the remainder from dividing by .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains three integers , and (, ).
Output
For each test case, output the maximum prize that can be obtained.
思路
设旋转 次落点为
令 则 因为 且
所以所有可达落点都满足
令 则 因而 可遍历
令 则可达集合为
最大值为
每组直接输出 时间复杂度
代码
#include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t; while (t --) { int l, a, b; cin >> l >> a >> b;
int g = gcd(l, b); int r = a % g; int ans = l - g + r;
cout << ans << endl; }}