码迷,mamicode.com
首页 > Web开发 > 详细

js中完数的输出

时间:2016-07-04 08:47:29      阅读:1257      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
var arrFactor = [];
var l = 0;
document.write("1000以内的完数有:" + "<br />");
for (var m = 3; m < 1001; m++) {
var M = m;
for (var p = 2; p < m; p ++) {
if (M % p == 0) {
arrFactor[l] = p;
l++;
}
}
var sum = 0;
for (var i = 0; i < arrFactor.length; i++) {
sum += arrFactor[i];
}
if (m == sum + 1) {
document.write(m + "<br />");
}
arrFactor.length = 0;
l = 0;
}
</script>
</head>
<body>

</body>
</html>

js中完数的输出

标签:

原文地址:http://www.cnblogs.com/SmallPotatoIT/p/5639383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!