Codeforces 1142A(性质、暴举)

队友和大佬都什么几种情况啥的……我是把终点都插了,起点随便选一个,暴举答案莽A。

 

 1 const int maxn = 1e5 + 5;
 2 ll n, k, a, b, aa, minn = INF, maxx = -1;
 3 set bb;
 4 
 5 ll gcd(ll a, ll b) {
 6     return b ? gcd(b, a % b) : a;
 7 }
 8 
 9 int main() {
10     cin >> n >> k >> a >> b;
11     ll T = n * k;
12     rep(i, 0, n - 1) {
13         ll p = (ll)i * k + 1;
14         bb.insert((p + b) % T);
15         bb.insert((p - b + T) % T);
16     }
17     aa = (1 + a) % T;
18     for(set::iterator it = bb.begin(); it != bb.end(); it++) {
19         ll t = *it;
20         ll ans = T / gcd(T, (t - aa + T) % T);
21         minn = min(minn, ans);
22         maxx = max(maxx, ans);
23     }
24     cout << minn << " " << maxx << endl;
25     return 0;
26 }

 

转载于:https://www.cnblogs.com/AlphaWA/p/10657841.html

你可能感兴趣的:(Codeforces 1142A(性质、暴举))