(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 ...
随机推荐
- iOS 之播放系统声音
导入框架: 代码: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface MsgPl ...
- Linux C 实现Ping功能的程序.
ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具.ping命令的工作原理是:向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文一模一样地传回给发送者,这 ...
- TMOUT
设置TMOUT可以踢用户,直接从shell端. 实际上如果ssh或telnet也可以在其配置里面设定.
- 高频(工作频率为13.56MHz)
在该频率的感应器不再需要线圈进行绕制,可以通过腐蚀活着印刷的方式制作天线.感应器一般通过负载调制的方式 的方式进行工作.也就是通过感应器上的负载电阻的接通和断开促使读写器天线上的电压发生变化,实现用远 ...
- PHP查看在线服务器与本地服务器支持函数差别
在本地开发好的程序.代码,当传到服务器后,经常会出现罢工的事情.这时候就要考虑开发环境和在线的环境是否完全一致了.这里所说的一致性,包括了容器的配置.php的配置等等.下面所要解决的只是其中一项,你的 ...
- Android源码的下载和编译
由于公司会安排我做硬解码这块,所以最近一直想研究一下Android源码,可是Android源码的下载真的挺麻烦的(可能是我第一次下载),参照网上的方法,没有一个可行的,现在就将我的下载过程和大家分享一 ...
- CSF 中的应用程序请求路由
编辑人员注释:本文章由 AzureCAT 团队的 Christain Maritnez 撰写. 应用程序请求路由(简称为 ARR)可能是 Microsoft 使用的技术中讨论得最少但极为重要的技术之一 ...
- JAVA GUI学习 - JTree树结构组件学习 ***
public class JTreeKnow extends JFrame { public JTreeKnow() { this.setBounds(300, 100, 400, 500); thi ...
- 代码收藏 JS实现页内查找定位功能
前部分为IE下搜索方法 用TextRange来实现 后部分为firefox.chrome下搜索方法 var nextIndex = 0; var searchValue = ''; var input ...
- Installing on CentOS/RHEL / KB forum / Ajenti
Installing on CentOS/RHEL / KB forum / Ajenti Ajenti → KB → Installation Is it?: Inappropriate Spam ...