Anti-primes: Difference between revisions

m (→‎{{header|Tiny BASIC}}: Works with (Tom Pittman's) TinyBasic.)
Line 786:
<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|QuickBASIC}}===
{{trans|ALGOL W}}
<syntaxhighlight lang="qbasic">
' Anti-primes
DECLARE FUNCTION DivisorCount (V%)
 
MaxAntiPrime% = 20
N% = 0: MaxDivisors% = 0: AntiPrimeCount% = 0
WHILE AntiPrimeCount% < MaxAntiPrime%
N% = N% + 1
Divisors% = DivisorCount(N%)
IF Divisors% > MaxDivisors% THEN
PRINT STR$(N%);
MaxDivisors% = Divisors%
AntiPrimeCount% = AntiPrimeCount% + 1
END IF
WEND
PRINT
END
 
FUNCTION DivisorCount (V%)
Total% = 1: N% = V%
WHILE N% MOD 2 = 0
Total% = Total% + 1
N% = N% \ 2
WEND
P% = 3
WHILE (P% * P%) <= N%
Count% = 1
WHILE N% MOD P% = 0
Count% = Count% + 1
N% = N% \ P%
WEND
P% = P% + 2
Total% = Total% * Count%
WEND
IF N% > 1 THEN Total% = Total% * 2
DivisorCount = Total%
END FUNCTION
</syntaxhighlight>
{{out}}
<pre>
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
 
512

edits