#include using namespace std; using ll = long long; #ifdef LOCAL #include #else #define debug(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int A, B, a, b; cin >> A >> B >> a >> b; for (int x = 0; x <= A * B; x++) { if (x % A == a && x % B == b) { cout << x << '\n'; return 0; } } }