304097: CF787A. The Monster
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
The Monster
题意翻译
给出$a,b,c,d$ 四个数,两个人在尖叫,第一个人在b,b+a,b+2a,b+3a......时刻尖叫,第二个人在d,d+c,d+2c,d+3c......时刻尖叫,问他们第一次在相同时刻尖叫是什么时候。 如果他们永远不可能同时尖叫,请输出 `-1`。题目描述
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+2a,b+3a,... $ and Morty screams at times $ d,d+c,d+2c,d+3c,... $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF787A/23c11249630f1c4252ef0b9cda8ec1bf9b317b5a.png)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.输入输出格式
输入格式
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 $ ).
输出格式
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
20 2
9 19
输出样例 #1
82
输入样例 #2
2 1
16 12
输出样例 #2
-1