Problem Description:
Let d (n) is defined as the sum of proper divisors of n (numbers less than n which divide into N).
If d (a) = B and d (b) = A, where a B, then A and B are a amicable pair and each of a and B are called amicable numbers.
For example, the proper divisors of the are 1, 2, 4, 5, A,,, and 110; therefore d (220) = 284. The proper divisors of 284 are 1, 2, 4, and 142; So d (284) = 220.
Evaluate the sum of all the amicable numbers under 10000.
Realize:
(function () {
var factor = function (n) {
var arr = new Array ();
for (var i = 1;i < n; i++)
{
if (n%i = 0 && arr.indexof (i) = = 1)
arr.push (i);
}
return arr;
}
var Sumarr = function (arr) {
var sum = 0;
for (var i = 0; i < arr.length i++)
sum + = Arr[i];
return sum;
}
for (var i = 2;i< 10000; i++)
{
var r1 = Sumarr (factor (i));
var r2 = Sumarr (factor (R1));
if (i = = R2 && i!= R1)
console.log ("NUM1: + i +", num2: "+ R1);
}"
) ();
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/