1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio();
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     bool isHappy(int n) 
12     {
13         while(n>6)
14         {
15             int next=0;
16             while(n)
17             {
18                 int a=n%10;
19                 next+=a*a;
20                 n/=10;
21             }
22             n=next;
23         }
24         return n==1;
25     }
26 };

找欢乐逗比数,一级一级算,直到最后数字小于6,小于6的数字中,只有1是欢乐数。

posted on 2018-05-22 18:52  高数考了59  阅读(115)  评论(0)    收藏  举报