#include using namespace std; int main(){ int A, B, a, b; cin >> A >> B >> a >> b; int x = 0; while (true){ if (x % A == a and x % B == b){ cout << x << endl; return 0; } x++; } }