#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int main() { llong a, b; cin >> a >> b; vector divisors; llong val = a + b; llong limit = (llong)sqrt(val)+1LL; for(llong i=2; i<=limit; i++) { while(val % i == 0 && val > 1) { val /= i; divisors.push_back(i); } if(val == 1) break; } if(val > 1) divisors.push_back(val); vector cands; set checked; cands.push_back(1); checked.insert(1); for(llong d: divisors) { int lim = cands.size(); rep(i, lim) { llong val = cands[i] * d; if(checked.count(val)) continue; checked.insert(val); cands.push_back(val); } } sort(cands.begin(), cands.end()); for(llong c: cands) { if(a == c || b == c) continue; if((a+b) % c == 0) { if((b+c) % a == 0) { if((c+a) % b == 0) { cout << c << "\n"; return 0; } } } } cout << -1 << "\n"; }