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