PivotOJ

Sun and Moon

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2022-2023BOJ 27590

문제

You recently missed an eclipse and are waiting for the next one! To see any eclipse from your home, the sun and the moon must be in alignment at specific positions. You know how many years ago the sun was in the right position, and how many years it takes for it to get back to that position. You know the same for the moon. When will you see the next eclipse?

입력

The input consists of two lines.

The first line contains two integers, dsd_s and ysy_s (0ds<ys50)(0 \le d_s < y_s \le 50), where dsd_s is how many years ago the sun was in the right position, and ysy_s is how many years it takes for the sun to be back in that position.

The second line contains two integers, dmd_m and ymy_m (0dm<ym50)(0 \le d_m < y_m \le 50), where dmd_m is how many years ago the moon was in the right position, and ymy_m is how many years it takes for the moon to be back in that position.

출력

Output a single integer, the number of years until the next eclipse. The data will be set in such a way that there is not an eclipse happening right now and there will be an eclipse within the next 50005\,000 years.

예제

예제 1

입력
3 10
1 2
출력
7
코드를 제출하려면 로그인하세요.