求完数的js版本
1000以内的完数
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
</body>
<script language="javascript">
<!--
Array.prototype.sum = function(){
var result = 0
for(var i=0; i<this.length; i++){
result += this[i]
}
return result
}
Number.prototype.ys = function(){
var result = []
var yb = this/2 + 1
for(var i=0; i<yb; i++){
if(this%i == 0){
result.push(i)
}
}
return result
}
var result = []
var length = 1000
for(var i=0; i<length; i++){
if(i.ys().sum() == i){
result.push(i)
}
}
alert(result)
var i=100
alert(i.ys())
</script>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
</body>
<script language="javascript">
<!--
Array.prototype.sum = function(){
var result = 0
for(var i=0; i<this.length; i++){
result += this[i]
}
return result
}
Number.prototype.ys = function(){
var result = []
var yb = this/2 + 1
for(var i=0; i<yb; i++){
if(this%i == 0){
result.push(i)
}
}
return result
}
var result = []
var length = 1000
for(var i=0; i<length; i++){
if(i.ys().sum() == i){
result.push(i)
}
}
alert(result)
var i=100
alert(i.ys())
</script>
</html>