(Problem 21)Amicable numbers
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的更多相关文章
- (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 ...
- (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 ...
- (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 ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (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 ...
- (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 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (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 ...
- (Problem 36)Double-base palindromes
The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...
随机推荐
- HTML+CSS笔记 CSS中级 缩写入门
盒子模型代码简写 回忆盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左. 语法: margin:10px 15p ...
- Protel99se轻松入门:特殊技巧和高级设置(一)
这里简单介绍一下自动布线和手动布线方面的设置问题 1.如何进入PCB的这个布线规则选项: 2.电气安全距离的设置 3.导线宽度的设置 4.学会了设置图层就可以做单面板以及多层板,而不只是双面板 5.布 ...
- [置顶] SQL日期类型
在做机房收费系统的时候,上下机,我觉得是我在整个系统中遇到最棘手的问题了,现在就给大家,分享一下,我是怎样解决的. SQL中有3中数据类型是关于日期的,每一种的用法是不同的,当你用错了,就会出现下面这 ...
- POJ 3228Gold Transportation(二分+最大流)
题目地址:POJ3288 这个题跟之前的一道题混了,感觉是一样的,所以连想都没怎么想就拆点然后求最短路然后二分求最大流了.结果连例子都只是,还一直以为又是哪里手残了..结果看了看例子,手算也确实不正确 ...
- block 解析 - 局部变量
局部变量 block内使用局部变量,一般都是截获变量(只读),截获离block初始化最近的一次的值. 引用官方文档: Stack (non-static) variables local to the ...
- Android SDK三种更新失败及其解决方法
更新Android SDK,居然失败了三次. 1.第一次失败 出现Failed to fetch URL错误提示 Failed to fetch URL https://dl-ssl.google.c ...
- 用python快速搭建WEB服务器
cmd下进入你要搞WEB项目的目录 输入↓方代码 python -m SimpleHTTPServer 端口号# 默认是8000 这样就启动了一个简单的WEB服务器
- SQL中distinct的用法(转)
原文:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...
- MyEclipse下JDBC-MySQL配置总结
原创文章,转载请注明:MyEclipse下JDBC-MySQL配置总结 By Lucio.Yang 新手,初期配置未成功,后将网上的方法几乎全部尝试才弄好,下面的方法全而不简练,希望高手指正. 1. ...
- Yii2 数据操作DAO
参考: http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.dao http://blog.csdn.net/hzqghost/artic ...