summaryrefslogtreecommitdiff
path: root/euler23.c
blob: bac7b08cd64411200ff3efaaa74b79ac1b54f501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#define MAX 100000

int sum_of_div(int n)
{
	int fd,fdsum=1,sum=1;
	while (n%2==0){
		fdsum<<=1;
		n>>=1;
	}
	sum *= (fdsum*2-1);
	fd = 3;
	while (n>1){
		fdsum=1;
		while (n%fd==0){
			fdsum*=fd;
			n/=fd;
		}
		sum *= (fdsum*fd-1)/(fd-1);
		fd += 2;
	}
	return sum;
}

int main()
{
	int n,i,j;
	int abundant[MAX];
	int sum_abundant[MAX]={0};
	int ans=0;
	for (i=1;i<=28123;++i){
		if (sum_of_div(i)>i*2){
			abundant[i]=1;
			for (j=1;j<=i&&j<=28123-i;++j){
				if (abundant[j]){
					sum_abundant[i+j]=1;
				}
			}
		}else{
			abundant[i]=0;
		}
	}
	for (int i=1;i<=28123;++i){
		if (!sum_abundant[i])
			ans+=i;
	}
	printf("%d\n",ans);
}