/* 整数(GCD,CRT)詰め合わせ */ #include // cout, endl, cin #include // string, to_string, stoi #include // vector #include // min, max, swap, sort, reverse, lower_bound, upper_bound #include // pair, make_pair #include // tuple, make_tuple #include // int64_t, int*_t #include // printf #include // map #include // queue, priority_queue #include // set #include // stack #include // deque #include // unordered_map #include // unordered_set #include // bitset #include // isupper, islower, isdigit, toupper, tolower #include #include #include #include #include #include #include #include #include using namespace std; // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される long extGCD(long a, long b, long &x, long &y) { if (b == 0) { x = 1; y = 0; return a; } long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } long GCD(long a,long b){ if(a=0)return a%m; return (m-(-a)%m)%m; } /* 中国剰余定理 */ bool CRT(long b1, long m1, long b2, long m2,long &r,long &m) { long p, q; long d = extGCD(m1, m2, p, q); if ((b2 - b1) % d != 0) return false; m = m1 * (m2/d); long tmp = (b2 - b1) / d * p % (m2/d); r = mod(b1 + m1 * tmp, m); return true; } bool CRT(const vector> &X,long &r,long &m) { int s = X.size(); r = X.front().first; m = X.front().second; bool ok = true; for(int i=1;i> X(3); for(auto&[a,m]:X)cin>>a>>m; long a,m; if(CRT(X,a,m)){ if(a==0)cout<