#include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int alpha, beta, a, b; cin >> alpha >> beta >> a >> b; int ans = 0; while (true) { if (ans % alpha == a && ans % beta == b) { break; } ans++; } cout << ans << endl; return 0; }