#include #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) long gcd(long a,long b){return b?gcd(b,a%b):a;} using namespace std; int main(void) { long a, b, k; vector yakusu; cin >> a >> b; for(int i = 1; i * i <= a + b; i++){ if((a + b) % i == 0){ yakusu.push_back(i); } } int len = yakusu.size(); rep(i, len){ yakusu.push_back((a + b) / yakusu[i]); } for(long m : yakusu){ if(m != a && m != b && (a + b) % m == 0 && (a + m) % b == 0 && (b + m) % a == 0){ cout << m << endl; return 0; } } cout << -1 << endl; return 0; }