#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define loop1(n) for(int loopt = 0; loopt < (n); loopt++) #define loop2(i,n) for((i) = 0; (i) < (n); (i)++) #define loop3(i,k,n) for((i) = (k); (i) < (n); (i)++) #define GET_NAME_LOOP(_2,_3,NAME,...) NAME #define loop(n,...) GET_NAME_LOOP(__VA_ARGS__,loop3,loop2,loop1)(n,__VA_ARGS__) #define rloop1(n) for(int loopt = (n)-1; loopt >= 0; loopt--) #define rloop2(i,n) for((i) = (n)-1; (i) >= 0; (i)--) #define rloop3(i,k,n) for((i) = (k)-1; (i) >= (n); (i)--) #define GET_NAME_RLOOP(_2,_3,NAME,...) NAME #define rloop(n,...) GET_NAME_RLOOP(__VA_ARGS__,rloop3,rloop2,rloop1)(n,__VA_ARGS__) #define outone cout << "First" << endl #define outtwo cout << "Second" << endl #define outyes cout << "Yes" << endl #define outno cout << "No" << endl #define outans cout << ans << endl #define all(i) i.begin(),i.end() //const ll mod = 998244353L; //const ll mod = 1e9+7L; //const double PI =3.14159265359d; //const double E =2.718281828d; int main() { int i,j,k; ll A,B,a,b; cin >> A >> B >> a >> b; while(a != b){ if(a > b) b+=B*(((a-b-1)/B)+1); else a+=A*(((b-a-1)/A)+1); } cout << a; }