Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //
- #define ll long long
- #define ull unsigned long long
- #define pb push_back
- #define mx 100010
- #define mod 1000000007
- #define inf INT_MAX
- #define pi acos(-1)
- #define endl '\n'
- #define fin freopen("input", "r", stdin)
- #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- //
- set<ll> se;
- vector<ll> v;
- void sieve()
- {
- bool isprime[mx];
- for (int i = 0; i <= mx; i++)
- {
- isprime[i] = true;
- }
- for (int i = 3; i * i <= mx; i += 2)
- {
- if (isprime[i])
- {
- for (int j = i * i; j <= mx; j += i + i)
- {
- isprime[j] = false;
- }
- }
- }
- v.pb(2);
- for (int i = 3; i <= mx; i += 2)
- {
- if (isprime[i])
- {
- v.pb(i);
- }
- }
- }
- void prime_divisor(ll x) {
- vector<ll>::iterator it;
- for (it = v.begin(); it != v.end(); it++) {
- if (*it > x) break;
- else if (x % *it == 0) {
- se.insert(*it);
- se.insert(x / *it);
- }
- }
- }
- int main() {
- sieve();
- ll t, a, b;
- cin >> t;
- scanf("%lld %lld", &a, &b);
- ll x = sqrt(a);
- prime_divisor(x);
- x = sqrt(b);
- prime_divisor(x);
- for (ll i = 1; i < t; i++) {
- scanf("%lld %lld", &a, &b);
- for (auto it1 = se.begin(); it1 != se.end(); it1++) {
- if (a % *it1 == 0 || b % *it1 == 0) {
- break;
- }
- else {
- se.erase(it1);
- }
- }
- }
- if (se.size() >= 1) cout << *se.begin() << endl;
- else cout << -1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement