A14107 | Three swimmers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line of the input contains a single integer $t$ ( $1 \leq t \leq 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 \leq p, a, b, c \leq 10^{18}$ ), 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.
Each line contains four integers $p$ , $a$ , $b$ and $c$ ( $1 \leq p, a, b, c \leq 10^{18}$ ), 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.
输出格式
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, \ldots$ minutes after the start time, the second swimmer is on the left side in $0, 4, 8, 12, \ldots$ minutes after the start time, and the third swimmer is on the left side in $0, 8, 16, 24, \ldots$ 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, \ldots$ minutes after the start time, the second swimmer is on the left side in $0, 10, 20, 30, \ldots$ minutes after the start time, and the third swimmer is on the left side in $0, 9, 18, 27, \ldots$ 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, \ldots$ 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.
In the second test case, the first swimmer is on the left side in $0, 6, 12, 18, \ldots$ minutes after the start time, the second swimmer is on the left side in $0, 10, 20, 30, \ldots$ minutes after the start time, and the third swimmer is on the left side in $0, 9, 18, 27, \ldots$ 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, \ldots$ 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted