问题描述:
Let d(n) be defined as the sum of proper divisors ofn(numbers less thannwhich divide evenly inton).
If d(a) =band d(b) =a, whereab, thenaandbare
an amicable pair and each ofaandbare called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.
实现:
(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);
}
})();
分享到:
相关推荐
友善的 知道数字是否友好的简单函数安装npm i - S is - amicable用法var isAmicable = require ( 'is-amicable' ) ;console . log ( isAmicable ( 220 ) ) ; // trueconsole . log ( isAmicable ( 284 ) ) ; // ...
amicable 友善的amiable 和蔼可亲的 anim 心灵,精神,生命 animal 动物animate 有生命的 ann ,enn 年 annual 一年的centennial 一世纪的 astro 星 astronomy 天文学astronaut 宇宙航行员 audi 听 audience 听众...
Being amicable Granted he is as busy as scores of celebrities, he never poses up with a poker face. In stead, he always takes the initiative to greet and communicate with others. Being considerate ...
将 'amicable.m' 文件放入您的 MATLAB 路径或工作目录并调用以下语法。 函数语法: 输出=友好(N2,N1) 其中,N2 为上限,N1 为下限,均为正整数。 如果只给出一个数字,则认为是上限, 默认的下限是 220(因为...
How do you get these guys to talk to one another, share data structures, and be generally amicable? This document discusses several methods of Interprocess Communication (IPC) that can accomplish this...
uses EDIT、MASM、LINK、DEBUG four steps of DOS commands pattern mainly , whose step is miscellaneous and trivial , the interface is not amicable , brings teaching and using about certain difficulty ...
amicable 友好的 analytical 善于分析的 apprehensive 有理解力的 aspiring 有志气的,有抱负的 audacious 大胆的,有冒险精神的 capable 有能力的,有才能的 careful 办理仔细的 candid 正直的