Advertisement
Guest User

B

a guest
May 19th, 2013
2,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cassert>
  4. #include <cctype>
  5. #include <complex>
  6. #include <ctime>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <deque>
  11. #include <functional>
  12. #include <fstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <map>
  16. #include <memory.h>
  17. #include <numeric>
  18. #include <queue>
  19. #include <set>
  20. #include <stack>
  21. #include <string>
  22. #include <sstream>
  23. #include <vector>
  24. #include <utility>
  25. #include <cmath>
  26. using namespace std;
  27.  
  28. #define pb push_back
  29. #define mp make_pair
  30. #define sz(a) (int)(a).size()
  31. #define all(a) (a).begin(), (a).end()
  32. #define rall(a) (a).rbegin(), (a).rend()
  33.  
  34. #define forn(i,n) for (int i=0; i<int(n); ++i)
  35. #define fornd(i,n) for (int i=int(n)-1; i>=0; --i)
  36. #define forab(i,a,b) for (int i=int(a); i<int(b); ++i)
  37.  
  38. typedef long long ll;
  39. typedef long double ld;
  40. typedef unsigned long long ull;
  41.  
  42. const int INF = (int) 1e9;
  43. const long long INF64 = (long long) 1e18;
  44. const long double eps = 1e-9;
  45. const long double pi = 3.14159265358979323846;
  46.  
  47. ll p,q,n;
  48. vector <ll> a;
  49. vector <ll> m;
  50.  
  51. bool read(){
  52.     if (!(cin >> p >> q >> n)) return false;
  53.     a.assign(n,0);
  54.     forn(i,n)
  55.         cin >> a[i];
  56.     return true;
  57. }
  58.  
  59. void calc(ll a, ll b){
  60.     if (a == 0 || b == 0) return;
  61.     ll q = a/b;
  62.     m.pb(q);
  63.     a -= b*q;
  64.     calc(b,a);
  65. }
  66.  
  67. void solve(){
  68.     if (n > 1 && a[n-1] == 1){
  69.         a[n-2]++;
  70.         a.pop_back();
  71.         n--;
  72.     }
  73.     m.clear();
  74.     calc(p,q);
  75.     bool ans = true;
  76.     if (sz(a)!=sz(m)) ans = false;
  77.     forn(i,min(sz(a),sz(m)))
  78.         ans = ans && (a[i]==m[i]);
  79.     if (ans)
  80.         puts("YES");
  81.     else
  82.         puts("NO");
  83. }
  84.  
  85. int main(){
  86. #ifdef dudkamaster
  87.     freopen("input.txt","rt",stdin);
  88.     freopen("output.txt","wt",stdout);
  89. #endif
  90.     while (read())
  91.         solve();
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement