308275: CF1492A. Three swimmers
Memory Limit:512 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Three swimmers
题意翻译
#### 题目描述 三个人在游泳,第 $0$ 分钟这三个人人在游泳池的左侧,之后他们开始来回游,游一个来回分别需要 $a,b,c$ 分钟。 你在第 $p$ 分钟到达游泳池的左侧,请问最少经过多少分钟,你看见一个人在游泳池的左侧? #### 输入格式 本题多测。第一行一个 $t$ 表示数据组数。 接下来 $t$ 行,每行四个整数 $p,a,b,c$。 #### 输出格式 $t$ 行,每行一个整数表示答案。 #### 数据范围 $1\le t \le1000$,$1\le p,a,b,c\le10^{18}$。题目描述
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.输入输出格式
输入格式
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.
输出格式
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