Advertisement
Josif_tepe

Untitled

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