import std; void main () { /* 後でちゃんと解く(多分)今は全探索 */ int A, B, a, b; readln.read(A, B, a, b); int ans = a; while (true) { if (ans % B == b) break; ans += A; } writeln(ans); } void read (T...) (string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }