#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; int p(int a, int b) { if (b == 0)return 1; if (b % 2 == 0) { return p((a*a) % MOD, b / 2); } else { return (p((a*a) % MOD, b / 2) * a) % MOD; } } int inv(int a) { return p(a, MOD - 2); } long long solve(long long m) { long long a = 0, b = 1, c = a + b; for (int i = 0; i < m * m; i++) { c = (a + b) % m; a = b; b = c; if (a == 0 && b == 1) return i + 1; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector pr(N); vector k(N); int res = 1; vector x; map mp; for (int i = 0; i < N; i++) { cin >> pr[i] >> k[i]; map tmp; tmp[pr[i]] = k[i] - 1; int x = solve(pr[i]); //cerr << "x=" << x << endl; for (int j = 2; j <= x; j++) { if (j*j > x)j = x; while (x%j == 0) { x /= j; tmp[j]++; } } if (x != 1)cerr << "ERROR x=" << x << endl; for (auto m : tmp) { mp[m.first] = max(mp[m.first], m.second); //mp[m.first] += m.second; } } for (auto m : mp) { //cerr << m.first << " " << m.second << endl; res = (res*p(m.first, m.second)) % MOD; } cout << res << endl; }