Responsive image

问题 1538 --找呀找呀找规律

1538: 找呀找呀找规律

时间限制: 1 Sec  内存限制: 128 MB
提交: 1  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

Given an array such as follows:
4, 16, 37, 58, 89, 145, 42, 20, 4, 16.
we found that the value of each element is the sum of the squares of all digits of the previous element(16 = 42, 37 = 12 + 62, 58 = 32 + 72 and so on). As you can see, the array is repeated with a cycle of length 8. Now, our questions is: given a starting integer, please output the cycle length. 

输入描述

Input will consist of multiple test cases. Each test case consists of a single line containing the starting
integer n(n<10000000).The input ends with an integer 0 which is not to be processed.

输出描述

For each input test case, please output the cycle length.

样例输入

4
1
0

样例输出

8
1

来源

zj 

[提交][状态]
ACM算法攻关部