text: gcd(b, a % b) : a; } struct IT { long long p; long long k; IT(long long p = 0, long long k = 0) : p(p), k(k) {} }; struct rec { IT p[1001]; long long num; void init(long long x) { for (long long i = 2; i * i <= x; ++i) { if (x % i == 0) { long long c = 0; while (x % i == 0) x /= i, c++; p[num++] = IT(i, c); } } if (x > 1) p[num++] = IT(x, 1); } IT query(long long x) { for (long long i = 0; i < num; ++i) if (p[i].p == x) return p[i]; return IT(x, 0); } } A[200], B[200]; long long n; IT A1[3507], B1[3507], A2[3507], B2[3507]; long long pri[3507], num; long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return a; } long long g = exgcd(b, a % b, y, x); y -= a / b * x; return g; } void inter(long long A, long long B, long long C, long long a, long long b, long long c, long long &x1, long long &x2) { while (a) { long long t = A / a; A -= t * a, B -= t * b, C -= t * c; swap(A, a); swap(B, b); swap(C, c); } if (c % b) puts("-1"), exit(0); x2 = -c / b; if ((C + B * x2) % A) puts("-1"), exit(0); x1 = (-C - B * x2) / A; } inline void UN(rec &a1, rec &b1, rec &a2, rec &b2) { num = 0; for (long long i = 0; i < a1.num; ++i) pri[num++] = a1.p[i].p; for (long long i = 0; i < a2.num; ++i) pri[num++] = a2.p[i].p; for (long long i = 0; i < b1.num; ++i) pri[num++] = b1.p[i].p; for (long long i = 0; i < b2.num; ++i) pri[num++] = b2.p[i].p; sort(pri, pri + num); num = unique(pri, pri + num) - pri; for (long long i = 0; i < num; ++i) A1[i] = a1.query(pri[i]); for (long long i = 0; i < num; ++i) A2[i] = a2.query(pri[i]); for (long long i = 0; i < num; ++i) B1[i] = b1.query(pri[i]); for (long long i = 0; i < num; ++i) B2[i] = b2.query(pri[i]); long long A = 0, B = 0, C = 0; long long flg1 = 0; long long x1, x2; for (long long i = 0; i < num; ++i) { long long a = B1[i].k, b = -B2[i].k, c = A1[i].k - A2[i].