diff options
Diffstat (limited to 'euler23.c')
-rw-r--r-- | euler23.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/euler23.c b/euler23.c new file mode 100644 index 0000000..bac7b08 --- /dev/null +++ b/euler23.c @@ -0,0 +1,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); +} + |