Main function.
37{
38 unsigned long sum = 0;
39 unsigned int MAX_N = 500;
40 if (argc == 2)
41 MAX_N = atoi(argv[1]);
42
43
44
45
46
47
48
49 char *flags = (
char *)
calloc(MAX_N,
sizeof(
char));
50
51 clock_t start_time = clock();
52 int i;
53
54 for (i = 10; i < MAX_N; i++)
55 {
56 if (flags[i] != 0)
57
58 continue;
59
61 if (b >= MAX_N)
62 flags[i] = -1;
63 else if (flags[b] == -1)
64 continue;
65
67 if (c == i && b != i)
68 {
69
70 flags[b] = 1;
71 flags[i] = 1;
72 sum += b + i;
73#ifdef DEBUG
74 printf("Amicable: %4d : %4d\n", i, b);
75#endif
76 }
77 else
78 {
79 flags[i] = -1;
80 if (b < MAX_N)
81 flags[b] = -1;
82 }
83 }
84
85 clock_t end_time = clock();
86
87 printf("\nTime taken: %.4g millisecond\n",
88 1e3 * (end_time - start_time) / CLOCKS_PER_SEC);
89 printf("Sum of all numbers = %lu\n", sum);
90
92 return 0;
93}
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26
#define calloc(elemCount, elemSize)
This macro replace the standard calloc function with calloc_dbg.
Definition: malloc_dbg.h:22
unsigned long sum_of_divisors(unsigned int N)
function to return the sum of proper divisors of N
Definition: sol1.c:13