CF1492A.Three swimmers
入门
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a minutes to swim across the entire pool and come back, exactly b minutes for the second swimmer and c minutes for the third. Hence, the first swimmer will be on the left side of the pool after 0, a, 2a, 3a, ... minutes after the start time, the second one will be at 0, b, 2b, 3b, ... minutes, and the third one will be on the left side of the pool after 0, c, 2c, 3c, ... minutes.
You came to the left side of the pool exactly p 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.
三位游泳者决定在游泳池里举办一场派对!中午时分,他们从游泳池的左侧出发开始游泳。
第一位游泳者恰好需要 a 分钟游完整个泳池并返回,第二位游泳者恰好需要 b 分钟,第三位游泳者恰好需要 c 分钟。因此,第一位游泳者将在起始时刻后的 0、a、2a、3a、… 分钟时回到泳池左侧;第二位游泳者将在 0、b、2b、3b、… 分钟时回到泳池左侧;第三位游泳者将在 0、c、2c、3c、… 分钟时回到泳池左侧。
你恰好在他们开始游泳后 p 分钟到达泳池左侧。请确定你需要等待多久,才会有一位游泳者抵达泳池左侧。
输入格式
The first line of the input contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contains test case descriptions, one per line.
Each line contains four integers p, a, b and c (1≤p,a,b,c≤1018), 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.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。接下来的 t 行每行描述一个测试用例。
每行包含四个整数 p、a、b 和 c(1≤p,a,b,c≤1018),分别表示你到达泳池的时间(从开始计时起的分钟数),以及三位游泳者各自游完整个泳池并返回所需的时间(单位:分钟)。
输出格式
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.
对于每个测试用例,输出一个整数——在有游泳者到达泳池左侧之前,你需要等待的时间(单位:分钟)。
输入输出样例
输入#1
4 9 5 4 8 2 6 10 9 10 2 5 10 10 9 9 9
输出#1
1 4 0 8
说明/提示
In the first test case, the first swimmer is on the left side in 0,5,10,15,… minutes after the start time, the second swimmer is on the left side in 0,4,8,12,… minutes after the start time, and the third swimmer is on the left side in 0,8,16,24,… minutes after the start time. You arrived at the pool in 9 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 0,6,12,18,… minutes after the start time, the second swimmer is on the left side in 0,10,20,30,… minutes after the start time, and the third swimmer is on the left side in 0,9,18,27,… minutes after the start time. You arrived at the pool 2 minutes after the start time and after 4 minutes meet the first swimmer on the left side.
In the third test case, you came to the pool 10 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 0,9,18,27,… minutes after the start time. You arrived at the pool 10 minutes after the start time and after 8 minutes meet all three swimmers on the left side.
在第一个测试用例中,第一位游泳者在起始时间后的 0,5,10,15,… 分钟时位于左侧;第二位游泳者在起始时间后的 0,4,8,12,… 分钟时位于左侧;第三位游泳者在起始时间后的 0,8,16,24,… 分钟时位于左侧。你在起始时间后 9 分钟到达泳池,并将在 1 分钟后于左侧遇到第一位游泳者。
在第二个测试用例中,第一位游泳者在起始时间后的 0,6,12,18,… 分钟时位于左侧;第二位游泳者在起始时间后的 0,10,20,30,… 分钟时位于左侧;第三位游泳者在起始时间后的 0,9,18,27,… 分钟时位于左侧。你在起始时间后 2 分钟到达泳池,并将在 4 分钟后于左侧遇到第一位游泳者。
在第三个测试用例中,你在起始时间后 10 分钟到达泳池。此时,三位游泳者均位于左侧。真是难得的好运!
在第四个测试用例中,所有游泳者均在起始时间后的 0,9,18,27,… 分钟时位于左侧。你在起始时间后 10 分钟到达泳池,并将在 8 分钟后于左侧同时遇到三位游泳者。
输入解题思路,AI测评打分。不知道怎么写?