Jump to content

Erdős-Nicolas numbers: Difference between revisions

Added C
(Added Go)
(Added C)
Line 272:
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
{{trans|C++}}
Run time about 46 seconds.
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
 
int main() {
const int maxNumber = 100000000;
int *dsum = (int *)malloc((maxNumber + 1) * sizeof(int));
int *dcount = (int *)malloc((maxNumber + 1) * sizeof(int));
int i, j;
for (i = 0; i <= maxNumber; ++i) {
dsum[i] = 1;
dcount[i] = 1;
}
for (i = 2; i <= maxNumber; ++i) {
for (j = i + i; j <= maxNumber; j += i) {
if (dsum[j] == j) {
printf("%8d equals the sum of its first %d divisors\n", j, dcount[j]);
}
dsum[j] += i;
++dcount[j];
}
}
free(dsum);
free(dcount);
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
61900800 equals the sum of its first 280 divisors
91963648 equals the sum of its first 142 divisors
</pre>
 
=={{header|C++}}==
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.