namespace BOJ
{
class No_18512
{
static void Main()
{
using StreamReader input = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
using StreamWriter output = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
int[] inputs = Array.ConvertAll(input.ReadLine().Split(), int.Parse);
int x = inputs[0];
int y = inputs[1];
int p1 = inputs[2];
int p2 = inputs[3];
int answer = -1;
int cnt = 0;
int px = p1, py = p2;
while(cnt < 1000)
{
if(px == py)
{
answer = px;
break;
}
if(px < py)
px += x;
else
py += y;
cnt++;
}
output.WriteLine(answer);
}
}
}
로직은 다 구현 하였지만 만나지 않는 경우를 어떤식으로 판별할지 하다가 다른 분들의 풀이를 참고하여 1000번 계산했을 때에도 같지 않다면 만나지 않는 경우로 판별하였다.
수학
브루트포스 알고리즘
정수론