-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Infinite_Sequence.java
56 lines (47 loc) · 1.32 KB
/
A_Infinite_Sequence.java
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
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class A_Infinite_Sequence {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int[] p = readArray();
int a = p[0];
int b = p[1];
int c = p[2];
if (c == 0) {
out.print(a == b ? "YES" : "NO");
} else if (c > 0) {
if (b < a) {
out.print("NO");
} else {
out.print((b - a) % c == 0 ? "YES" : "NO");
}
} else if (c < 0) {
if (b > a) {
out.print("NO");
} else {
out.print((b - a) % c == 0 ? "YES" : "NO");
}
}
out.close();
}
private static String read() throws IOException {
return in.readLine();
}
private static int readInt() throws IOException {
return Integer.parseInt(in.readLine());
}
private static int[] readArray() throws IOException {
String[] line = in.readLine().split("\\s");
int[] a = Arrays.stream(line).mapToInt(Integer::parseInt).toArray();
return a;
}
private static int[] readSortedArray() throws IOException {
String[] line = in.readLine().split("\\s");
int[] a = Arrays.stream(line).mapToInt(Integer::parseInt).sorted().toArray();
return a;
}
}