1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <iostream> #include <cstring> #include <string> using namespace std; bool trace[10000]; int random(int n) { int a=n*n; int arr[10]; int k=8; while(a) { arr[k]=a%10; k-=1; a/=10; } for(int i=k;i>=1;i--) arr[i]=0; int num=0; for(int i=3;i<=6;i++) { num*=10; num+=arr[i]; } return num; } int main() { int n,k; int cnt; while(cin>>n) { if(n==0) break; memset(trace,0,sizeof(trace)); cnt=1; int num=n; trace[num]=1; while(1) { num=random(num); if(trace[num]==0) { trace[num]=1; cnt+=1; } else break; } cout<<cnt<<"\n"; } return 0; } |