-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid0021.c
More file actions
40 lines (30 loc) · 680 Bytes
/
id0021.c
File metadata and controls
40 lines (30 loc) · 680 Bytes
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
// Licensed under the MIT License.
// Amicable Numbers
#include "../lib/euler.h"
#include "../lib/factor_iterator.h"
int main(void)
{
int sum = 0;
struct Sieve primes;
clock_t start = clock();
int* d = malloc(10000 * sizeof * d);
d[0] = 0;
d[1] = 1;
euler_assert(d);
euler_ok(sieve(&primes, 0));
for (int a = 2; a < 10000; a++)
{
d[a] = factor_divisor_sum(a, &primes) - a;
}
for (int a = 2; a < 10000; a++)
{
int b = d[a];
if (a != b && b < 10000 && a == d[b])
{
sum += a;
}
}
free(d);
finalize_sieve(&primes);
return euler_submit(21, sum, start);
}