| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2365 人关注过本帖
标题:[没人气,抄道题] 快乐数
取消只看楼主 加入收藏
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
结帖率:91.67%
收藏
已结贴  问题点数:100 回复次数:0 
[没人气,抄道题] 快乐数
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

现在的问题是,给定一个正整数,判定它是否为快乐数
搜索更多相关主题的帖子: following positive replace include numbers 
2015-08-05 12:43
快速回复:[没人气,抄道题] 快乐数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010672 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved