Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int number;
- cin >> number;
- long long N;
- cin >> N;
- int a = number / 100;
- int b = (number / 10) % 10;
- int c = number % 10;
- if(N <= 3) {
- if(N == 1) {
- cout << a ;
- }
- else if(N == 2) {
- cout << b;
- }
- else {
- cout << c;
- }
- return 0;
- }
- int pc;
- for(int i = 3; i < N; i++) {
- pc = c;
- c = (a + b + c) % 10;
- a = b;
- b = pc;
- }
- cout << c << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement