forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.java
More file actions
29 lines (27 loc) · 938 Bytes
/
B.java
File metadata and controls
29 lines (27 loc) · 938 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
import java.io.*;
import java.math.*;
import java.util.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
BigInteger p = new BigInteger(sc.next()),
q = new BigInteger(sc.next());
int n = sc.nextInt();
long[] a = new long[n];
for(int i = 0; i < n; ++i) {
a[i] = sc.nextLong();
}
BigInteger x = BigInteger.valueOf(a[n-1]), y = BigInteger.ONE;
for(int i = n-2; i >= 0; --i) {
BigInteger tmp = y;
y = x;
x = tmp;
x = x.add(y.multiply(BigInteger.valueOf(a[i])));
}
if (x.multiply(q).equals(y.multiply(p))) System.out.println("YES");
else System.out.println("NO");
}
sc.close();
}
}