#include #include #include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll a,b,c,d; cin>>a>>b>>c>>d; int x = 0; while(true){ if(x%a==c&&x%b==d){ cout<