#include using namespace std; using ll = long long; constexpr ll MOD = 1000000007; ll power(const ll p, const ll k) { if (k == 0) return 1; if (k % 2 == 1) { return power(p, k - 1) * p % MOD; } else { const ll pp = power(p, k / 2); return pp * pp % MOD; } } constexpr int MAX = 10000000; constexpr int SQRT = 3163; bool isprime[SQRT]; array, 2> mul(const array, 2>& m1, const array, 2>& m2, const ll mod) { array, 2> ans{{{0, 0}, {0, 0}}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { (ans[i][j] += m1[i][k] * m2[k][j] % mod) %= mod; } } } return ans; } array, 2> power(const array, 2>& m, const ll n, const ll mod) { if (n == 0) return array, 2>{{{1, 0}, {0, 1}}}; if (n % 2 == 1) { return mul(power(m, n - 1, mod), m, mod); } else { const auto pp = power(m, n / 2, mod); return mul(pp, pp, mod); } } bool isperiod(const ll n, const ll p) { const array, 2> id{{{1, 0}, {0, 1}}}; const array, 2> mat{{{1, 1}, {1, 0}}}; const auto ans = power(mat, n, p); return ans == id; } int main() { fill(isprime, isprime + SQRT, true); vector prime; for (int i = 2; i < SQRT; i++) { if (not isprime[i]) continue; prime.push_back(i); for (int j = 2; i * j < SQRT; j++) { isprime[i * j] = false; } } int N; cin >> N; vector ind(MAX, 0); for (int i = 0; i < N; i++) { ll p, k; cin >> p >> k; if (p == 2) { ind[2] = max(ind[2], k); ind[3] = max(ind[3], 1LL); } else if (p == 5) { ind[2] = max(ind[2], 2LL); ind[5] = max(ind[5], k); } else { const ll PER = (p % 5 == 1 or p % 5 == 4) ? p - 1 : 2 * p + 2; ll per = PER; for (ll d = 2; d * d <= PER; d++) { if (isperiod(d, p)) { per = min(per, d); } if (d * d != per and isperiod(PER / d, p)) { per = min(per, PER / d); } } for (const ll P : prime) { if (per % P != 0) continue; ll num = 0; while (per % P == 0) { per /= P; num++; } ind[P] = max(ind[P], num); } ind[p] = max(ind[p], k - 1); if (per != 1) { ind[per] = max(ind[per], 1LL); } } } ll ans = 1; for (int i = 0; i < MAX; i++) { // if (ind[i] > 0) { // cerr << i << ": " << ind[i] << endl; // } (ans *= power(i, ind[i])) %= MOD; } cout << ans << endl; return 0; }