Non-abundant sums
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
题目解析
非充足数之和
一个数的所有真因子之和等于它本身的称之为完美数,一个数的所有真因子之和小于它本身的叫做不足数,而大于它本身的叫充足数。12就是最小的充足数。最小的两个重组数之和就是12+12=24了。根据数学分析我们知道,所有大于28123的数都可以写作两个充足数的和。然而这个上限不能通过分析进一步减少。
求所有不能由两个重组书加和得来的数的和。
程序代码 C
#include <stdio.h>
#include <string.h>
#define N 28150
int f[N];
int b[N];
int find(int n){
int i,sum=0;
for(i=1;i<n;i++){
if(n%i==0)
sum+=i;
if(sum>n)
return 1;
}
return 0;
}
int main()
{
int i,j,k,num;
long long sum;
memset(f,0,sizeof(f));
memset(b,0,sizeof(b));
num=0;sum=0;
for(i=1;i<N;i++)
if(find(i))
b[num++]=i;
/*for(i=0;i<num;i++)
printf("%d ",b[i]);*/
for(i=0;i<num;i++){
for(j=0;j<num;j++){
int s=b[i]+b[j];
if(s<N)
f[s]=1;
}
}
for(i=1;i<=28123;i++)
if(!f[i])
sum+=i,printf("%d ",i);
printf("%lld\n",sum);
return 0;
}