301611: CF305B. Continued Fractions

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Continued Fractions

题意翻译

给定$p,q,a_1,a_2,...,a_n,$若$\frac{p}{q}=a_1+\frac{1}{a_2+\frac{1}{...+\frac{1}{a_n}}}$则输出"YES",否则输出"NO".(不包含引号) $n<=90,1<=q<=p<=10^{18},1<=a_i<=10^{18}.$

题目描述

A continued fraction of height $ n $ is a fraction of form ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF305B/19ade84928d3d628a6e212b03adbbf8bc0856736.png). You are given two rational numbers, one is represented as ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF305B/ae456f9650d5b3ca46e54c303d07fec088f6ad5e.png) and the other one is represented as a finite fraction of height $ n $ . Check if they are equal.

输入输出格式

输入格式


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.

输出格式


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

输入输出样例

输入样例 #1

9 4
2
2 4

输出样例 #1

YES

输入样例 #2

9 4
3
2 3 1

输出样例 #2

YES

输入样例 #3

9 4
3
1 2 4

输出样例 #3

NO

说明

In the first sample ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF305B/a7429bd0927ab226e00de904e1ba240c58b09318.png). In the second sample ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF305B/a01a984749367ddde5131c663127bc347e31f0a2.png). In the third sample ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF305B/4db9464841d1b99996f6c98f75df85058aee123f.png).

Input

题意翻译

给定$p,q,a_1,a_2,...,a_n,$若$\frac{p}{q}=a_1+\frac{1}{a_2+\frac{1}{...+\frac{1}{a_n}}}$则输出"YES",否则输出"NO".(不包含引号) $n<=90,1<=q<=p<=10^{18},1<=a_i<=10^{18}.$

加入题单

算法标签: