RosettaCodeData/Task/Almost-prime/FutureBasic/almost-prime.basic
2026-02-01 16:33:20 -08:00

28 lines
716 B
Text

local fn almostPrimes
uint8 i = 1, primes( 50 ) = {2,3,5,7,11,13,17,19,23,29,31,¬
37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,¬
131,137,139,149,151,157,163,167,173,179,109,113,127}
while 10 > mda_count 5 // Quit when k=5 list is filled
int k = 0, x = 0, n = i
while n > 1
if (n % primes(x)) then x++ else k++ : n /= primes(x)
wend
mda_add k = i
i++
wend
end fn
window 1, @"Almost primes"
fn almostPrimes
printf @" Almost primes from 2 to %d with k prime factors:", mda_integer 5 (9)
for int k = 1 to 5
printf @"\n k=%d:\b",k
for int i = 0 to 9
printf @"%5d\b", mda_integer k ( i )
next
printf @" + %2d more.", (mda_count k) - 10
next
HandleEvents