Advertisement
Josif_tepe

Untitled

Mar 6th, 2022
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 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. int main() {
  10.     string n;
  11.     cin >> n;
  12.     int f = (n[0] - '0');
  13.     int s = (n[1] - '0');
  14.     int t = (n[2] - '0');
  15.    
  16.     for(int i = 0; i < 1000; i++) {
  17.         int tmp = t;
  18.         t = (t + s + f) % 10;
  19.         n += (t + '0');
  20.         int sz = (int) n.size();
  21.         if(n[0] == n[sz - 3] and n[1] == n[sz - 2] and n[2] == n[sz - 1]) {
  22.             n.erase(n.end() - 1);
  23.             n.erase(n.end() - 1);
  24.             n.erase(n.end() - 1);
  25.             break;
  26.         }
  27.         f = s;
  28.         s = tmp;
  29.     }
  30.     long long K;
  31.     cin >> K;
  32.     int sz = (int) n.size();
  33.     long long pos = K % sz;
  34.     if(pos == 0) {
  35.         cout << n[sz - 1] << endl;
  36.     }
  37.     else {
  38.         cout << n[pos - 1] << endl;
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement