// Codeforces Round #184 (Div. 2) B Continued Fractions
import java.io.*;
import java.math.*;
import java.util.*;
//Codeforces
public class MainCodeforces2 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;
private static void solve() throws IOException
{
long p = in.nextLong();
long q = in.nextLong();
int n = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
long fractiona = 1;
long fractionb = 1;
long xa = 1;
long xb = 1;
if (n == 1)
fractiona = a[0];
else {
xa = 1;
xb = a[n - 1];
for (int i = n - 1; i >= 1; i--) {
double xbd = (a[i - 1] * (double) xb) + xa;
if (xbd > 1e18) {
out.println("NO");
return;
}
long oldxb = xb;
xb = (a[i - 1] * xb) + xa;
xa = oldxb;
}
fractiona = xb;
fractionb = xa;
}
BigInteger bp = new BigInteger(String.valueOf(p));
BigInteger bq = new BigInteger(String.valueOf(q));
BigInteger bfa = new BigInteger(String.valueOf(fractiona));
BigInteger bfb = new BigInteger(String.valueOf(fractionb));
if (bp.multiply(bfb).equals(bq.multiply(bfa)))
// if (p * fractionb == q * fractiona)
out.println("YES");
else
out.println("NO");
// out.println();
}
public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
LOCAL_TEST = (cname.equals("ALPHA530"));
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
public String nextLine() throws IOException {
return inp.nextLine();
}
}
}
No comments:
Post a Comment