欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1492A.Three swimmers
Three swimmers
Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.
It takes the first swimmer exactly minutes to swim across the entire pool and come back, exactly minutes for the second swimmer and minutes for the third. Hence, the first swimmer will be on the left side of the pool after , , , , ... minutes after the start time, the second one will be at , , , , ... minutes, and the third one will be on the left side of the pool after , , , , ... minutes.
You came to the left side of the pool exactly minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.
Input
The first line of the input contains a single integer () — the number of test cases. Next lines contains test case descriptions, one per line.
Each line contains four integers , , and (), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.
Output
For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.
Note
In the first test case, the first swimmer is on the left side in minutes after the start time, the second swimmer is on the left side in minutes after the start time, and the third swimmer is on the left side in minutes after the start time. You arrived at the pool in minutes after the start time and in a minute you will meet the first swimmer on the left side.
In the second test case, the first swimmer is on the left side in minutes after the start time, the second swimmer is on the left side in minutes after the start time, and the third swimmer is on the left side in minutes after the start time. You arrived at the pool minutes after the start time and after minutes meet the first swimmer on the left side.
In the third test case, you came to the pool minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!
In the fourth test case, all swimmers are located on the left side in minutes after the start time. You arrived at the pool minutes after the start time and after minutes meet all three swimmers on the left side.
Samples
4
9 5 4 8
2 6 10 9
10 2 5 10
10 9 9 9
1
4
0
8
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |