#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ vector > prime_factorization(long long num) { vector > res; for (long long i = 2; i * i <= num; ++i) { if (num % i != 0) continue; int exponent = 0; while (num % i == 0) { ++exponent; num /= i; } res.emplace_back(i, exponent); } if (num != 1) res.emplace_back(num, 1); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int a, b; cin >> a >> b; auto p = prime_factorization(a + b); p.emplace_back(1, 0); for (auto aut : p) if (aut.first != a && aut.first != b) { if ((aut.first + a) % b == 0 && (aut.first + b) % a == 0) { cout << aut.first << '\n'; return 0; } } cout << -1 << '\n'; return 0; }