#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 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 md) { int n = mr.size(); ll x = 0, m = 1; for (int i = 0; i < n; i++) { ll b = mr[i].second - x; ll t = b * mod_inv(m, mr[i].first) % mr[i].first; (x += m * t) %= md; m *= mr[i].first; } return x; } 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() { ios::sync_with_stdio(false), cin.tie(0); 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; }