#include #include using namespace std; using lint=int64_t; #include template void div(vector &vec,T n) { for(T i=1;i*i<=n;i++) { if(n%i==0) { vec.push_back(i); if(i*i!=n) vec.push_back(n/i); } } return; } bool check(lint A,lint B,lint C) { if(A==C)return false; if(B==C)return false; if((A+B)%C!=0)return false; if((B+C)%A!=0)return false; if((A+C)%B!=0)return false; return true; } int main() { lint A,B; cin >> A >> B; vector divs; div(divs,A+B); sort(divs.begin(),divs.end()); for(auto& i:divs) { if(check(A,B,i)) { cout << i << endl; return 0; } } cout << -1 << endl; return 0; }