using System; using System.Collections.Generic; using System.Linq; // https://yukicoder.me/problems/no/2558 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("3 5 1 2"); //7 } else if (InputPattern == "Input2") { WillReturn.Add("1 3000 0 0"); //0 } else if (InputPattern == "Input3") { WillReturn.Add("998 2443 5 3"); //2203589 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); long[] wkArr = InputList[0].Split(' ').Select(pX => long.Parse(pX)).ToArray(); long A = wkArr[0]; long B = wkArr[1]; long a = wkArr[2]; long b = wkArr[3]; for (long I = 0; I <= A * B; I++) { if (I % A == a && I % B == b) { Console.WriteLine(I); return; } } } }