Advertisement
Josif_tepe

Untitled

Mar 6th, 2022
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <cstring>
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(false);
  12.     string n;
  13.     cin >> n;
  14.     int F = (n[0] - '0');
  15.     int S = (n[1] - '0');
  16.     int T = (n[2] - '0');
  17.    
  18.     for(int i = 0; i < 1000; i++) {
  19.         int tmp = T;
  20.         T = (T + S + F) % 10;
  21.         F = S;
  22.         S = tmp;
  23.         n += (T + '0');
  24.         int sz = (int) n.size();
  25.         if(n[0] == n[sz - 3] and n[1] == n[sz - 2] and n[2] == n[sz - 1]) {
  26.             n.erase(n.end() - 1);
  27.             n.erase(n.end() - 1);
  28.             n.erase(n.end() - 1);
  29.             break;
  30.         }
  31.     }
  32.     long long K;
  33.     cin >> K;
  34.     K %= n.size();
  35.     if(K == 0) {
  36.         cout << n[n.size() - 1] << endl;
  37.     }
  38.     else {
  39.         cout << n[K - 1] << endl;
  40.     }
  41.  
  42.     return 0;
  43. }
  44. //1753531933519559931371191113597
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement