听完钟皓曦大神的课之后使用了他的大数翻倍法,可以用来解中国剩余定理,那还能优化完之后用来求解exCRT吗?
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL n, x, y, z, q, P, Q, k;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
void dashufanbei(LL &x, LL &y, LL z, LL q)
{
if (x < z) // y > q
swap(x, z), swap(y, q);
while (y % z != q)
y += x;
x = lcm(x, z);
}
int main()
{
cin >> n;
cin >> x >> y;
for (LL i = 2; i <= n; i++)
{
cin >> z >> q;
dashufanbei(x, y, z, q);
}
cout << y;
return 0;
}