Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int p, n;
- cin >> p >> n;
- vector<int> v;
- for(int i = 0; i < 100; i++) {
- int tmp = p;
- int treta_cifra = tmp % 10;
- tmp /= 10;
- int vtora_cifra = tmp % 10;
- tmp /= 10;
- int prva_cifra = tmp % 10;
- tmp /= 10;
- int sleden_broj = prva_cifra * prva_cifra + vtora_cifra * vtora_cifra + treta_cifra * treta_cifra;
- v.push_back(p);
- p = sleden_broj;
- if(i + 1 == n) {
- cout << p << endl;
- return 0;
- }
- }
- vector<int> reps;
- for(int i = 0; i < v.size(); i++) {
- int se_povtoruva = -1;
- for(int j = i + 1; j < v.size(); j++) {
- if(v[i] == v[j]) {
- se_povtoruva = j - 1;
- break;
- }
- }
- if(se_povtoruva != -1) {
- for(int j = i; j <= se_povtoruva; j++) {
- reps.push_back(v[j]);
- }
- n -= i;
- break;
- }
- }
- int sz = reps.size();
- if(n % sz == 0) {
- cout << reps[sz - 1] << endl;
- }
- else {
- cout << reps[n % sz] << endl;
- }
- return 0;
- }
- // 89 145 42 20 4 16 37 58
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement