#include #define rep(i,a,b) for(int i=a;i> v; void add(ll a, ll m) { v.push_back({ a, m }); } // x = a (mod m) set enumpr(ll n) { set V; for (ll i = 2; i*i <= n; i++) while (n%i == 0) V.insert(i), n /= i; if (n>1) V.insert(n); return V; } ll ext_gcd(ll p, ll q, ll& x, ll& y) { if (q == 0) return x = 1, y = 0, p; ll g = ext_gcd(q, p%q, y, x); y -= p / q*x; return g; } ll inv(ll p, ll q) { ll xx, yy, g = ext_gcd(p, q, xx, yy); if (xx<0) xx += q, yy -= p; return xx; } ll solve(ll mo = 1000000007) { string s; int N = v.size(); set P; vector num; rep(i, 0, N) { set S = enumpr(v[i].second); for(ll r : S) P.insert(r);} num = vector(N, 0); for(ll r : P) { int y = 0; rep(x, 0, N) { num[x] = 1; int j = v[x].second; while (j%r == 0) j /= r, num[x] *= r; if (num[y] > V2; rep(x, 0, N) if (v[x].second>1) V2.emplace_back(v[x].second, v[x].first); sort(V2.begin(), V2.end()); v = V2; N = v.size(); rep(y, 0, N) rep(x, 0, y) { ll k = v[y].second - v[x].second; if (k<0) k += v[y].first; v[y].second = k*inv(v[x].first, v[y].first) % v[y].first; } ll ret = 0; for (int x = N - 1; x >= 0; x--) ret = (ret*v[x].first + v[x].second) % mo; return ret; } }; ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ //--------------------------------------------------------------------------------------------------- void _main() { CRT crt; int N; cin >> N; rep(i, 0, N) { int m, a; cin >> a >> m; crt.add(a, m); } ll ans = crt.solve(); //if (ans == 0) ans = lcm(b, lcm(d, f)); cout << ans << endl; }