js中完数的输出

<!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>

posted @ 2016-07-04 08:31  Small_Potato_IT  阅读(732)  评论(0编辑  收藏  举报