// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second #include #include #include namespace rklib { struct SimpleSieve { std::vector is_prime; std::vector prime; SimpleSieve(int n) { is_prime.resize(n + 1, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; ++i) { if (!is_prime[i]) continue; prime.push_back(i); for (int j = 2; i * j <= n; ++j) { is_prime[i * j] = false; } } } }; struct Sieve { std::vector min_factor, prime; Sieve(int n) { min_factor.resize(n + 1, 0); for (int i = 2; i <= n; ++i) { if (min_factor[i] == 0) { min_factor[i] = i; prime.push_back(i); } for (int x : prime) { if (x * i > n || x > i) break; min_factor[x * i] = x; } } } std::vector> prime_factor(int n) { std::vector> res; while (n > 1) { if (res.empty() || res.rbegin()->first != min_factor[n]) { res.emplace_back(min_factor[n], 1); } else ++res.rbegin()->second; n /= min_factor[n]; } return res; } void divisor_dfs(std::vector> &p, int t, int cur, std::vector &res) { if (cur == (int)p.size()) { res.push_back(t); return; } divisor_dfs(p, t, cur + 1, res); for (int _ = 0; _ < p[cur].second; ++_) { t *= p[cur].first; divisor_dfs(p, t, cur + 1, res); } } std::vector get_divisor(int n, bool sorted = false) { std::vector res; auto p = prime_factor(n); divisor_dfs(p, 1, 0, res); if (sorted) sort(res.begin(), res.end()); return res; } }; } // namespace rklib #include #include #include namespace rklib { template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template bool chmin_non_negative(T &a, const T &b) { if (a < 0 || a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } } // namespace rklib using namespace std; using namespace rklib; using lint = long long; using pii = pair; using pll = pair; int prime_factors[10'000'010]; int main() { int K; scanf("%d", &K); int n; rep(i, K) { int p, e; scanf("%d%d", &p, &e); prime_factors[p] += e; if (i == K - 1) n = p; } Sieve sv(n); int cnt_nonzero = K; rep(r, n) { { int tmp = n - r; while (tmp != 1) { int mf = sv.min_factor[tmp]; if (prime_factors[mf] == 0) ++cnt_nonzero; --prime_factors[mf]; if (prime_factors[mf] == 0) --cnt_nonzero; tmp /= mf; } } { int tmp = r + 1; while (tmp != 1) { int mf = sv.min_factor[tmp]; if (prime_factors[mf] == 0) ++cnt_nonzero; ++prime_factors[mf]; if (prime_factors[mf] == 0) --cnt_nonzero; tmp /= mf; } } if (cnt_nonzero == 0) { printf("%d %d\n", n, r + 1); return 0; } } printf("%d %d\n", -1, -1); }