#include #include #include #include #define REP(i,a,n) for(int i=a;i prime_factor(ll n){ vector Clist; for(int i=1;i*i <= n;i++){ if(n%i==0){ Clist.push_back(i); if((n/i)==i)continue; Clist.push_back(n/i); } } sort(Clist.begin(),Clist.end()); return Clist; } int main(){ long long A,B,ans=-1,min=1e9; cin >> A >> B; vector pf; pf=prime_factor(A+B); /** for(auto itr=Clist.begin();itr!=Clist.end();itr++){ cout << *itr << " "; } cout << endl; **/ for(auto itr=pf.begin();itr!=pf.end();itr++){ if((A+*itr)%B!=0)continue; if((B+*itr)%A!=0)continue; if(A==*itr||B==*itr)continue; if(min<*itr)continue; min=*itr; ans=*itr; break; } cout << ans << endl; }