[没人气,抄道题] 快乐数
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.对于一个正整数n,计算这个n的每位的平方和,重复这个过程,要么最终变为1,要么陷入一个无限的循环中。变为1的称为快乐数。
例如 19 就是一个快乐数,因为
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1 最终变为了1
例如 4 就不是一个快乐数,因为
4^2 = 16
1^2 + 6^2 = 37
3^2 + 7^2 = 58
5^2 + 8^2 = 89
8^2 + 9^2 = 145
1^2 + 4^2 + 5^2 = 42
4^2 + 2^2 = 20
2^2 + 0^2 = 4 又变成当初的4了,永远不会变成1
现在的问题是,给定一个正整数,判定它是否为快乐数