Codeforces Round 184 (Div. 2)
B
Continued Fractions
Codeforces
1700
原题
← AC →
翻译中…

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

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*p*, *q*$ $(1 ≤ *q* ≤ *p* ≤ 10^{18})$ — the numerator and the denominator of the first fraction.

翻译中…

The second line contains integer $*n*$ $(1 ≤ *n* ≤ 90)$ — the height of the second fraction. The third line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ 10^{18})$ — the continued fraction.

翻译中…

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

In the first sample image.

翻译中…

In the second sample image.

翻译中…

In the third sample image.

翻译中…

样例

Input #1
9 4
2
2 4
Output #1
YES
InputCopy OutputCopy
Input #2
9 4
3
2 3 1
Output #2
YES
InputCopy OutputCopy
Input #3
9 4
3
1 2 4
Output #3
NO
InputCopy OutputCopy
题目信息
题号
305B
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。