Advertisement
Josif_tepe

Untitled

Mar 2nd, 2024
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5.     int p, n;
  6.     cin >> p >> n;
  7.    
  8.     for(int i = 0; i < n; i++) {
  9.         int tmp = p;
  10.         int sum = 0;
  11.         while(tmp > 0) {
  12.             int cifra = tmp % 10;
  13.             cifra *= cifra;
  14.             sum += cifra;
  15.            
  16.             tmp /= 10;
  17.         }
  18.         p = sum;
  19.     }
  20.     cout << p << endl;
  21.     return 0;
  22. }
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement