fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define endl '\n'
  5. #define int long long
  6.  
  7. const int N = 2e5, oo = 2e18, MOD = 1e9+7;
  8.  
  9.  
  10.  
  11. void add(string& a, string& b) {
  12. reverse(a.begin(), a.end());
  13. reverse(b.begin(), b.end());
  14. int c = 0;
  15. int i = 0;
  16. auto get = [&](int i) {
  17. if (i >= a.size()) return 0;
  18. return (a[i] - '0');
  19. };
  20.  
  21. auto add = [&](int i, int d) {
  22. if (i >= a.size()) a.push_back(d + '0');
  23. a[i] = d + '0';
  24. };
  25. for (; i < b.size(); i++) {
  26. int s = get(i) + (b[i] - '0') + c;
  27. c = s / 10;
  28. add(i, s % 10);
  29. }
  30. // cout << c << ' ' << i << endl;
  31. if (c) {
  32. add(i, c + get(i));
  33. }
  34.  
  35. reverse(a.begin(), a.end());
  36.  
  37. }
  38.  
  39. void solve() {
  40. int c; cin >> c;
  41. string n; cin >> n;
  42. string s = "1", b = "1";
  43.  
  44. for (int i = 0; i < 1e3; i++) {
  45. if (s == n) {
  46. cout << "YES\n";
  47. return;
  48. }
  49. string temp = s;
  50. add(s, b);
  51. b = temp;
  52. }
  53. cout << "NO\n";
  54. }
  55.  
  56.  
  57. signed main() {
  58. ios_base::sync_with_stdio(false);
  59. cin.tie(NULL); cout.tie(NULL);
  60. // #ifndef ONLINE_JUDGE
  61. // freopen("input.txt", "r", stdin);
  62. // freopen("output.txt", "w", stdout);
  63. // #endif
  64. int t; t = 1;
  65. // cin >> t;
  66. while (t--) solve();
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
NO