Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int b;
- cin >> b;
- int a[200];
- int j = 0;
- for(int i = 0; i < 100; i++) {
- int tmp = n;
- int broj = 0;
- a[j] = tmp;
- j++;
- while(tmp > 0) {
- int cifra = tmp % 10;
- broj += cifra * cifra;
- tmp /= 10;
- }
- n = broj;
- if(i == b - 1) {
- cout << broj << endl;
- return 0;
- }
- }
- int ciklus[200];
- int sz = 0;
- int najden_ciklus = 0;
- for(int i = 0; i < 100; i++) {
- for(j = i + 1; j < 100; j++) {
- if(a[i] == a[j]) {
- najden_ciklus = 1;
- for(int k = i; k < j; k++) {
- ciklus[sz] = a[k];
- sz++;
- }
- break;
- }
- }
- if(najden_ciklus == 1) {
- b -= i;
- break;
- }
- }
- int ost = b % sz;
- if(ost == 0) {
- cout << ciklus[sz - 1] << endl;
- }
- else {
- cout << ciklus[ost] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement