-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeSwimmers.java
More file actions
44 lines (35 loc) · 1001 Bytes
/
Copy pathThreeSwimmers.java
File metadata and controls
44 lines (35 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
public class ThreeSwimmers {
public static long mini(long a, long b, long c) {
long min = 0;
if ((a < b) && (a < c)) {
min = a;
} else if (b < c) {
min = b;
} else {
min = c;
}
return min;
}
public static void solve(long p, long a, long b, long c) {
long ans;
if (p % a == 0 || p % b == 0 || p % c == 0)
System.out.println(0);
else {
ans = mini(a - p % a, b - p % b, c - p % c);
System.out.println(ans);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t > 0) {
long p = in.nextLong();
long a = in.nextLong();
long b = in.nextLong();
long c = in.nextLong();
solve(p, a, b, c);
t--;
}
}
}