```
#include <bits/stdc++.h>
using namespace std;
int check(int n,int count)
{
static int dup;
int rem,sum = 0;
while(n!=0){
rem = n%10;
sum += pow(rem,2);
n = n/10;
}
count++;
if(count==1){
dup = sum;
}
if(count>1 && dup==sum){
return -1;
}
if(sum==1){
return count;
}
check(sum,count);
}
int main() {
int n;
cin>>n;
int res = check(n,0);
cout<<res;
return 0;
}
```

LINK TO THE QUESTION: https://www.spoj.com/problems/HPYNOS/