senb1

krsu 2242

Mar 10th, 2023
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /*
  2. * by: senb1
  3. */
  4. #include <algorithm>
  5. #include <iomanip>
  6. #include <iostream>
  7. #include <locale>
  8. #include <numeric>
  9. #include <cstring>
  10.  
  11. #include <deque>
  12. #include <list>
  13. #include <map>
  14. #include <stack>
  15. #include <string>
  16. #include <vector>
  17. #include <array>
  18. #include <queue>
  19. #include <set>
  20.  
  21. using namespace std;
  22.  
  23. #define all(x) x.begin(), x.end()
  24. #define rall(x) x.rbegin(), x.rend()
  25. #define yes cout<<"YES\n"
  26. #define no cout<<"NO\n"
  27. #define fr first
  28. #define sc second
  29.  
  30. typedef long long ll;
  31. typedef unsigned long long ull;
  32. typedef long double ld;
  33.  
  34. const int maxn = 1e6 + 10;
  35. const long long mod = 2021;
  36. const int inf = 1e9;
  37.  
  38. ll binpow(ll a, ll b) {
  39.     ll res = 1;
  40.     while (b > 0) {
  41.         if (b & 1)
  42.             res = res * a;
  43.         a = a * a;
  44.         b >>= 1;
  45.     }
  46.     return res;
  47. }
  48.  
  49. int main() {
  50.     ios::sync_with_stdio(0); cin.tie(0);
  51.     //cout << fixed << setprecision(12);
  52.    
  53.     ull n;
  54.     cin >> n;
  55.  
  56.     int a = 0, b = 1;
  57.     vector<int> v = { a, b };
  58.  
  59.     for (ull i = 1; i <= n + 3; i++) {
  60.         int c = b;
  61.         b = (b + a) % mod;
  62.         a = c;
  63.  
  64.         if (a == 0 && b == 1) {
  65.             v.pop_back();
  66.             break;
  67.         }
  68.         else
  69.             v.push_back(b);
  70.        
  71.     }
  72.  
  73.     n = n % v.size();
  74.     cout << v[n + 3];
  75. }
  76.  
  77. /*
  78. * a 0
  79. * b 0
  80. * c 0
  81. * d 97
  82. * e 63
  83. */
  84.  
Advertisement
Add Comment
Please, Sign In to add comment