Anti-primes: Difference between revisions
Content deleted Content added
Alextretyak (talk | contribs) |
Catskill549 (talk | contribs) |
||
Line 32: | Line 32: | ||
{{out}} |
{{out}} |
||
<pre>1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560</pre> |
<pre>1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560</pre> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f ANTI-PRIMES.AWK |
|||
# converted from Go |
|||
BEGIN { |
|||
print("The first 20 anti-primes are:") |
|||
while (count < 20) { |
|||
d = count_divisors(++n) |
|||
if (d > max_divisors) { |
|||
printf("%d ",n) |
|||
max_divisors = d |
|||
count++ |
|||
} |
|||
} |
|||
printf("\n") |
|||
exit(0) |
|||
} |
|||
function count_divisors(n, count,i) { |
|||
if (n < 2) { |
|||
return(1) |
|||
} |
|||
count = 2 |
|||
for (i=2; i<=n/2; i++) { |
|||
if (n % i == 0) { |
|||
count++ |
|||
} |
|||
} |
|||
return(count) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 20 anti-primes are: |
|||
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |