#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define DEBUG_ //!!提出時にコメントアウト!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; //何もしない文 #endif #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換 #define pb push_back typedef long long LL; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef pair PLL; template std::string printVector(const std::vector &data) { std::stringstream ss; std::ostream_iterator out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } const int MOD = 1e9+7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; vector > prime_factorize(long long n) { vector > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); LL A,B; cin >> A >> B; auto fac = prime_factorize(A+B); for(auto p : fac) { LL cand = p.first; if((cand+B)%A == 0 && (cand+A)%B == 0) { if(cand != A && cand != B) { cout << cand << endl; return 0; } } } cout << "-1" << endl; }