#include using namespace std; using ll = long long; using pll = pair; const ll mod = 1e9 + 7; ll pow(ll x, int n) { ll res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } ll mod_pow(ll x, ll n, ll md) { ll res = 1; while (n) { if (n & 1) (res *= x) %= md; (x *= x) %= md; n >>= 1; } return res; } ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } ll mod_inv(ll a, ll md) { ll x, y; extgcd(a, md, x, y); return (x % md + md) % md; } ll garner(vector mr, ll mod) { mr.emplace_back(mod, 0); int n = mr.size(); vector coffs(n, 1); vector constants(n, 0); for (int i = 0; i < n - 1; i++) { ll v = (mr[i].second - constants[i]) * mod_inv(coffs[i], mr[i].first) % mr[i].first; if (v < 0) v += mr[i].first; for (int j = i + 1; j < n; j++) { (constants[j] += coffs[j] * v) %= mr[j].first; (coffs[j] *= mr[i].first) %= mr[j].first; } } return constants.back(); } vector> factorize(ll n) { vector> res; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res.emplace_back(i, 0); while (n % i == 0) { res.back().second++; n /= i; } } } if (n != 1) { if (!res.empty() && res.back().first == n) res.back().second++; else res.emplace_back(n, 1); } return res; } bool add_factor(ll x, ll m, map>& facts) { auto fs = factorize(m); for (auto p : fs) { if (!facts.count(p.first)) { facts[p.first] = make_pair(p.second, x % pow(p.first, p.second)); continue; } auto q = facts[p.first]; if ((x - q.second) % pow(p.first, min(p.second, q.first)) != 0) return false; if (p.second > q.first) { facts[p.first] = make_pair(p.second, x % pow(p.first, p.second)); } } return true; } int main() { int N; cin >> N; map> facts; bool ok = true; for (int i = 0; i < N; i++) { int X, Y; cin >> X >> Y; ok = ok && add_factor(X, Y, facts); if (!ok) { cout << -1 << endl; return 0; } } bool zero = true; vector mr; for (auto p : facts) { mr.emplace_back(pow(p.first, p.second.first), p.second.second); if (p.second.second != 0) zero = false; } ll res = garner(mr, mod); if (zero) { res = 1; for (auto p : facts) { (res *= pow(p.first, p.second.first)) %= mod; } } cout << res << endl; return 0; }