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以下所有亲和数之和。

// (Problem 21)Amicable numbers
// Completed on Wed, 24 Jul 2013, 06:07
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h> int FactorSum(int n) //计算n的所有小于n的因素和
{
int i;
int sum=;
for(i=; i<=n/; i++)
{
if(n%i==)
sum+=i;
}
return sum;
} int main()
{
int t,i=;
int sum=;
while(i<)
{
t=FactorSum(i);
if(t!=i && FactorSum(t)==i)
sum+=i;
i++;
}
printf("%d\n",sum);
return ;
}
Answer:
31626

(Problem 21)Amicable numbers的更多相关文章

  1. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  2. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  3. (Problem 28)Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  4. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  5. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  6. (Problem 72)Counting fractions

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

  7. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  8. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  9. (Problem 36)Double-base palindromes

    The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...

随机推荐

  1. linux下挂载第二块硬盘

    1.第一步:添加硬盘/新建分区(fdisk) a.查看当前系统所有硬盘及分区情况:fdisk -lb.在指定的硬盘(例:/dev/sda)上创建分区:fdisk /dev/sda , 根据提示进行下一 ...

  2. 射频识别技术漫谈(27)——CPU卡概述

    智能卡按安全级别可以分为三类:存储器卡.逻辑加密卡和CPU卡,其中CPU卡是安全级别最高的.从“CPU”这个名字可以看出,CPU卡最大的特点就是卡片里面有一个"CPU",有了CPU ...

  3. 脑波设备mindwave介绍

    脑波,又称之为脑电波,是人大脑发出的电波,非常的微弱,只能通过设备来检测. 人的脑波在不同状态下,会不同,因此可以通过脑波来量化分析人的精神状态. 科学家讲脑电波分为四种,以下为详细解释(摘自百度百科 ...

  4. hdoj 1532 Drainage Ditches(最大网络流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用Edmonds ...

  5. Node log4js

    一个完善的项目,日志是必不可少的一部分,在node开发中,调试成了让开发者头疼的部分,因此日志成为在node中帮助调试的一个重要模块. 一.Node使用Log4js 1.使用npm工具,在命令行中 执 ...

  6. out/target/common/obj/PACKAGING/public_api.txt android.view.KeyEvent.KEYCODE_has changed value from

    编译出错: out/target/common/obj/PACKAGING/public_api.txt:22549: error 17: Field android.view.KeyEvent.KE ...

  7. 使用AJAX日历控件,显示某些日期(CalendarExtender)

    1. The HTML Markup <div> <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1&q ...

  8. BZOJ 2882: 工艺( 后缀自动机 )

    把串S复制成SS然后扔进后缀自动机里, 从根选最小的儿子走, 走N步就是答案了...一开始还想写个treap的...后来觉得太麻烦..就用map了... ----------------------- ...

  9. javascript学习(9)——[设计模式]单例

    单例模式,相信大家对此都不陌生,我们主要讲下javascript中几个比较常见的设计模式: (1).普通的单体 (2).具有局部变量的强大单体 (3).惰性单体 (4).分支单体 下面我们就一一进行介 ...

  10. JavaScript基础知识----document对象

    对象属性document.title                 //设置文档标题等价于HTML的<title>标签document.bgColor               //设 ...