Advertisement
Josif_tepe

Untitled

Mar 11th, 2022
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int number;
  7.     cin >> number;
  8.     long long N;
  9.     cin >> N;
  10.     int a = number / 100;
  11.     int b = (number / 10) % 10;
  12.     int c = number % 10;
  13.     if(N <= 3) {
  14.         if(N == 1) {
  15.             cout << a ;
  16.         }
  17.         else if(N == 2) {
  18.             cout << b;
  19.         }
  20.         else {
  21.             cout << c;
  22.         }
  23.         return 0;
  24.     }
  25.     int pc;
  26.     for(int i = 3; i < N; i++) {
  27.         pc = c;
  28.         c = (a + b + c) % 10;
  29.         a = b;
  30.         b = pc;
  31.     }
  32.     cout << c << endl;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement