Description of the problem:
Let D (n) being defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If D (a) = b and D (b) = a, where a b, then a and b is an amicable pair and each of a and b is called amicable numbers.
For example, the proper divisors of 1, 2, 4, 5, ten, one,,, 110; therefore d (220) = 284. The proper divisors of 284 are 1, 2, 4, 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.indexo f (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) Conso Le.log ("NUM1:" + i + ", num2:" + R1);}}) ();
Amicable numbers--Javascript implementation