3604.Continued Fractions

Time Limit: 1s Memory Limit: 256MB

A continued fraction of height n is a fraction of form 3604_1.png. You are given two rational numbers, one is represented as 3604_2.png and the other one is represented as a finite fraction of height n. Check if they are equal.

Input Format(From the terminal/stdin)

Input The first line contains two space-separated integers p,q (1 \le q \le p \le 1018) - the numerator and the denominator of the first fraction.The second line contains integer n (1 \le n \le 90) - the height of the second fraction. The third line contains n space-separated integers a1,a2,...,an (1 \le ai \le 1018) - the continued fraction.Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output Format(To the terminal/stdout)

Output Print "YES" if these fractions are equal and "NO" otherwise.

Sample Input 1

Copy
9 4
2
2 4
 · \n
 \n
 · \n

Sample Output 1

Copy
YES
   \n

Sample Input 2

Copy
9 4
3
2 3 1
 · \n
 \n
 · · \n

Sample Output 2

Copy
YES
   \n

Sample Input 3

Copy
9 4
3
1 2 4
 · \n
 \n
 · · \n

Sample Output 3

Copy
NO
  \n

Hints

In the first sample 3604_3.png.In the second sample 3604_4.png.In the third sample 3604_5.png.

Submit

请先 登录

© 2025 FAQs