#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; long long int INF = 3e18; double Pi = 3.1415926535897932384626; vector G[500005]; vector

tree[500010]; priority_queue pql; priority_queue

pqp; //big priority queue priority_queue ,greater > pqls; priority_queue ,greater

> pqps; //small priority queue //top pop int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,-1,1}; char dir[] = "DRUL"; //ll bit[500005]; //↓,→,↑,← #define p(x) cout<> a >> b; assert(1 <= a && a <= 1000000000); assert(1 <= b && b <= 1000000000); for(i=1;i*i<=a+b;i++){ if((a+b)%i == 0){ if((a+i)%b==0 && (b+i)%a==0 && a != i && b != i)x[num++] = i; if((a+(a+b)/i)%b == 0 && (b+(a+b)/i)%a == 0 && a != (a+b)/i && b != (a+b)/i)x[num++] = (a+b)/i; } } sort(x,x+num); if(num == 0){ p(-1); }else{ p(x[0]); } return 0; }