Skip to content

Instantly share code, notes, and snippets.

@rendon
Created September 27, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rendon/eee76a03286b06a3b8c52ef53de46064 to your computer and use it in GitHub Desktop.
Save rendon/eee76a03286b06a3b8c52ef53de46064 to your computer and use it in GitHub Desktop.
#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