欧拉计划007 [23] Non-abundant sums

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值