Created
September 27, 2021 18:03
-
-
Save rendon/eee76a03286b06a3b8c52ef53de46064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using std::vector; | |
bool cycleIsIncomplete(vector<int> const & sequence, int a, int b, int idx) { | |
unsigned m = sequence.size(); | |
int aa = sequence[(idx-2+m)%m]; | |
int bb = sequence[(idx-1+m)%m]; | |
return aa != a || bb != b; | |
} | |
int main() { | |
int a, b; | |
std::cin >> a >> b; | |
vector<int> sequence{a, b, 0}; | |
int count = 0; | |
unsigned idx = 2; | |
std::cout << a << " " << b << " "; | |
unsigned m = sequence.size(); | |
do { | |
int x = sequence[(idx-2+m)%m]; | |
int y = sequence[(idx-1+m)%m]; | |
sequence[idx] = (x + y) % 10; | |
std::cout << sequence[idx] << " "; | |
idx = (idx + 1) % m; | |
count++; | |
} while (cycleIsIncomplete(sequence, a, b, idx)); | |
std::cout << "\n" << count << "\n"; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment