CF787A.The Monster
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2_a_, b + 3_a_, ... and Morty screams at times d, d + c, d + 2_c_, d + 3_c_, ....

The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
一个怪物正在另一颗星球上追捕瑞克和莫蒂。他们吓得不时尖叫。更准确地说,瑞克在时刻 b, b+a, b+2a, b+3a, … 尖叫,而莫蒂在时刻 d, d+c, d+2c, d+3c, … 尖叫。

如果他们在某一时刻同时尖叫,怪物便会抓住他们。因此,怪物想知道它将在何时抓住他们(即他们首次同时尖叫的时刻),或者他们将永远不会同时尖叫。
输入格式
The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).
The second line contains two integers c and d (1 ≤ c, d ≤ 100).
输入的第一行包含两个整数 a 和 b(1 ≤ a, b ≤ 100)。
输入的第二行包含两个整数 c 和 d(1 ≤ c, d ≤ 100)。
输出格式
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
输出瑞克和莫蒂第一次同时尖叫的时间,如果他们永远不会同时尖叫,则输出 -1。
输入输出样例
输入#1
20 2 9 19
输出#1
82
输入#2
2 1 16 12
输出#2
-1
说明/提示
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
在第一个样例测试用例中,Rick 的第 5 次尖叫和 Morty 的第 8 次尖叫均发生在时刻 82。
在第二个样例测试用例中,Rick 的所有尖叫均发生在奇数时刻,而 Morty 的所有尖叫均发生在偶数时刻,因此他们永远不会在同一时刻尖叫。
输入解题思路,AI测评打分。不知道怎么写?