#include #include #include using namespace std; int Enjapma(int A, int B) { if (A == B) { return -1; } int D = A + B; vector div; for (int i = 1; i < (D / 2); i++) { if (D%i == 0) { div.insert(div.begin(), i); } } vector Bans; vector::iterator a = div.begin(); while (a != div.end()) { if ((A + *a) % B == 0) { Bans.insert(Bans.begin(), *a); } a++; } int ans = -1; vector::iterator b = Bans.begin(); while (b != Bans.end()) { if ((B + *b) % A == 0) { ans = *b; } b++; } if (A == ans) { ans = -1; } if (B == ans) { ans = -1; } return ans; } int main() { int A, B; cout << "A B > "; cin >> A >> B; cout << Enjapma(A, B) << endl; system("pause"); return 0; }