Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

Content added Content deleted
(Upgraded to 'full' task.)
(Added C)
Line 334: Line 334:
{{out}}
{{out}}
<pre>Same as FreeBASIC entry.</pre>
<pre>Same as FreeBASIC entry.</pre>

=={{header|C}}==
{{trans|Wren}}
The faster version.
<syntaxhighlight lang="c">#include <stdio.h>
#include <locale.h>

int divisorCount(int n) {
int i, j, count = 0, k = !(n%2) ? 1 : 2;
for (i = 1; i*i <= n; i += k) {
if (!(n%i)) {
++count;
j = n/i;
if (j != i) ++count;
}
}
return count;
}

int main() {
int i, numbers50[50], count = 0, n = 1, dc;
printf("First 50 numbers which are the cube roots of the products of their proper divisors:\n");
setlocale(LC_NUMERIC, "");
while (1) {
dc = divisorCount(n);
if (n == 1|| dc == 8) {
++count;
if (count <= 50) {
numbers50[count-1] = n;
if (count == 50) {
for (i = 0; i < 50; ++i) {
printf("%3d ", numbers50[i]);
if (!((i+1) % 10)) printf("\n");
}
}
} else if (count == 500) {
printf("\n500th : %'d\n", n);
} else if (count == 5000) {
printf("5,000th : %'d\n", n);
} else if (count == 50000) {
printf("50,000th: %'d\n", n);
break;
}
}
++n;
}
return 0;
}</syntaxhighlight>

{{out}}
<pre>
First 50 numbers which are the cube roots of the products of their proper divisors:
1 24 30 40 42 54 56 66 70 78
88 102 104 105 110 114 128 130 135 136
138 152 154 165 170 174 182 184 186 189
190 195 222 230 231 232 238 246 248 250
255 258 266 273 282 285 286 290 296 297

500th : 2,526
5,000th : 23,118
50,000th: 223,735
</pre>


=={{header|C++}}==
=={{header|C++}}==