#include using namespace std; #include long long invmod(long long a,long long m) { long long s=a%m,t=m,sx=1,sy=0,tx=0,ty=1; while(s%t!=0) { long long f=s/t; long long u=s-t*f,ux=sx-tx*f,uy=sy-ty*f; s=t,sx=tx,sy=ty; t=u,tx=ux,ty=uy; } if(tx<0)tx+=m; return tx; } long long garner(const vector&x,const vector&m,const int mod=0)//*=x mod m { vectorv(x.size()); v[0]=x[0]; for(int i=1;i mapM,S; mapisp; main() { int N;cin>>N; for(int i=0;i>a>>b; for(int j=2;j*j<=b;j++) { if(b%j==0) { int p=1; while(b%j==0) { p*=j; b/=j; } isp[j]=true; S[j]=max(S[j],p); if(j!=p)S[p]=j; if(M.find(p)!=M.end()) { if(M[p]!=a%p) { cout<<-1<1) { S[b]=max(S[b],b); isp[b]=true; if(M.find(b)!=M.end()) { if(M[b]!=a%b) { cout<<-1<A,B; for(map::iterator it=M.begin();it!=M.end();it++) { int b=it->second,a=it->first; int t=a; if(isp.find(t)==isp.end())t=S[t]; t=S[t]; if(M[t]%a!=b) { cout<<-1<::iterator it=isp.begin();it!=isp.end();it++) { int a=S[it->first]; int b=M[a]; A.push_back(b); B.push_back(a); } long long ans=garner(A,B,1e9+7); if(ans==0) { ans=1; for(int i=0;i