求助exCRT 18pts

P4777 【模板】扩展中国剩余定理(EXCRT)

@[Ziqqurat](/user/483928) ```cpp #include <bits/stdc++.h> #define int __int128 using namespace std; const int N = 1e5 + 5; int n, r1, r2, m1, m2; long long _tmp,__tmp; //Hallo Ha Ha Ha Ha Hallo int exgcd(int a, int b, int &x, int &y) { if(!b) return x = 1, y = 0, a; int d = exgcd(b, a % b, x, y); int t = x; x = y; y = t - a / b * y; return d; } int gcd(int a, int b) { if(!b) return a; return gcd(b, a % b); } void merge() { //I I I hate you int d = gcd(m1, m2); int p1 = m1 / d, p2 = m2 / d, l = m1 * m2 / d; int c = (r2 - r1) / d, x, y; //cout << p1 << ' ' << p2 << ' ' << d << ' ' << l << ' ' << c << "\n"; exgcd(p1, p2, x, y); //cout << x << ' ' << y << "\n"; int xx = (r1 + c * ((x + l) % l) % l * m1 % l + l) % l; m1 = l, r1 = xx; //cout << xx << "\n"; return ; } signed main() { cin>>_tmp; n=_tmp; for (int i = 1; i <= n; ++i) { int e, f; cin>>_tmp>>__tmp; e=_tmp,f=__tmp; if(i == 1) m1 = e, r1 = f; else { m2 = e, r2 = f; merge(); } } printf("%lld\n", (long long)(r1)); return 0; } ```
by MarSer020 @ 2023-02-25 10:42:22


@[_MarSser020_](/user/475112) 哦哦哦原来__int128可以强制转化一下来读入输出的啊谢谢隔壁老哥啊哈
by Tsukinaga_Ichiyo @ 2023-02-25 10:44:10


|