Let d(n) be 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 are an amicable pair and each of a and b are 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.
原题大意:
d(n)定义为n 的所有真因子(小于 n 且能整除 n 的整数)之和。
如果 d(a) = b 并且 d(b) = a, 且 a b, 那么 a 和 b 就是一对相亲数(amicable pair),并且 a 和 b 都叫做亲和数(amicable number)。
例如220的真因子是 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 和 110; 因此 d(220) = 284. 284的真因子是1, 2, 4, 71 和142; 所以d(284) = 220.
计算10000以下所有亲和数之和。
#include<stdio.h> #include<math.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<stdbool.h> int FactorSum(int n) //计算n的所有小于n的因素和 { int i; int sum=1; for(i=2; i<=n/2; i++) { if(n%i==0) sum+=i; } return sum; } int main() { int t,i=2; int sum=0; while(i<10000) { t=FactorSum(i); if(t!=i && FactorSum(t)==i) sum+=i; i++; } printf("%d\n",sum); return 0; }
Answer:
|
31626 |
相关推荐
友善的 知道数字是否友好的简单函数安装npm i - S is - amicable用法var isAmicable = require ( 'is-amicable' ) ;console . log ( isAmicable ( 220 ) ) ; // trueconsole . log ( isAmicable ( 284 ) ) ; // ...
deal with individual chunks of a problem in parallel. Of course, its easiest if the processes don't have to communicate with one another while they're running and can just sit there doing their own ...
amicable 友善的amiable 和蔼可亲的 anim 心灵,精神,生命 animal 动物animate 有生命的 ann ,enn 年 annual 一年的centennial 一世纪的 astro 星 astronomy 天文学astronaut 宇宙航行员 audi 听 audience 听众...
汇编集成环境的开发 摘 要 传统的汇编程序开发主要在DOS...4.2.5 文本处理 21 4.2.6 格式修改 22 4.2.7 汇编源文件的操作 23 4.2.8任务栏图标及帮助 26 4.3 软件测试 27 4.4 总结 30 致 谢 31 参 考 文 献 32 附 录 33
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(因为...
amicable 友好的 analytical 善于分析的 apprehensive 有理解力的 aspiring 有志气的,有抱负的 audacious 大胆的,有冒险精神的 capable 有能力的,有才能的 careful 办理仔细的 candid 正直的