Problem 21 solution
More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Main function.
38 unsigned long sum = 0;
39 unsigned int MAX_N = 500;
41 MAX_N = atoi(argv[1]);
49 char *flags = (
char *)
calloc(MAX_N,
sizeof(
char));
51 clock_t start_time = clock();
54 for (i = 10; i < MAX_N; i++)
63 else if (flags[b] == -1)
74 printf(
"Amicable: %4d : %4d\n", i, b);
85 clock_t end_time = clock();
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);
#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
◆ sum_of_divisors()
unsigned long sum_of_divisors |
( |
unsigned int |
N | ) |
|
function to return the sum of proper divisors of N
15 unsigned long sum = 1 + N;
17 for (
unsigned int i = 2; i * i < N; i++)