B. Weakened Common Divisor
思路:我们需要找到一个数能够是的ai%k==0||aj%k==0 ,对于第一对,如果存在这样的数,那么代表他一定能够被第一对的其中的一个整除,所以我们如果进行质因数分解,那么他一定等于第一对中的某个质因数,所以我们只需要找到第一对的所有的质因数,然后看看那个质因数能够被这n对的整除,如果没有则输出-1
// Problem: B. Weakened Common Divisor
// Contest: Codeforces - Codeforces Round 505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
// URL: https://codeforces.com/problemset/problem/1025/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<set>
#include<unordered_map>
#include<ctime>
#include<cstdlib>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PIII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}
int T,hackT;
int n,m,k;
PII w[N];
int st[N];
void get(vector<int> &vis,int x) {
for(int i=2;i<=x/i;i++) {
if(x%i==0) {
vis.push_back(i);
while(x%i==0) x/=i;
}
}
if(x!=1) vis.push_back(x);
}
void solve() {
n=read();
for(int i=1;i<=n;i++) w[i].fi=read(),w[i].se=read();
vector<int> vis;
get(vis,w[1].fi),get(vis,w[1].se);
sort(vis.begin(),vis.end());
vis.erase(unique(vis.begin(),vis.end()),vis.end());
for(int i=0;i<vis.size();i++) {
for(int j=1;j<=n;j++) {
if(w[j].fi%vis[i]==0||w[j].se%vis[i]==0) st[i]++;
}
}
for(int i=0;i<vis.size();i++) {
if(st[i]==n) {
printf("%d\n",vis[i]);
return ;
}
}
printf("-1\n");
}
int main() {
// init();
// stin();
// scanf("%d",&T);
T=1;
while(T--) hackT++,solve();
return 0;
}