fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3.  
  4. #define print(a) for (auto x : a) cout << x << " "; cout << endl
  5. #define print_upto(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
  6. #define take(x,n) for(int i=0;i<n;i++) cin>>x[i];
  7.  
  8. #define watch(x) cout << (#x) << " is " << (x) << "\n"
  9. #define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
  10.  
  11. using namespace std;
  12.  
  13. ll n;
  14. map<ll, ll> mp;
  15.  
  16. ll func(ll n) {
  17. if (n == 1 || n == 2)
  18. return n;
  19.  
  20. if (mp[n] != 0)
  21. return mp[n];
  22.  
  23. return mp[n] = func(n - 1) + func(n - 2);
  24. }
  25.  
  26. int main() {
  27.  
  28. ios_base::sync_with_stdio(false);
  29. cin.tie(0);
  30. cout.tie(0);
  31.  
  32. // #ifndef ONLINE_JUDGE
  33. // freopen("input.txt", "r", stdin);
  34. // freopen("output.txt", "w", stdout);
  35. // freopen("error.txt" , "w" , stderr);
  36. // #endif
  37.  
  38. cin >> n;
  39.  
  40. mp[0] = 1;
  41. mp[1] = 1;
  42. mp[2] = 1;
  43.  
  44. ll ans = func(n);
  45. cout << ans << "\n";
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 4348KB
stdin
Standard input is empty
stdout
1