A   k-Almost-prime   is a natural number   



n


{\displaystyle n}

   that is the product of   



k


{\displaystyle k}

   (possibly identical) primes.



Example

1-almost-primes,   where   



k
=
1


{\displaystyle k=1}

,   are the prime numbers themselves.

2-almost-primes,   where   



k
=
2


{\displaystyle k=2}

,   are the   semiprimes.



Task

Write a function/method/subroutine/... that generates k-almost primes and use it to create a table here of the first ten members of k-Almost primes for   



1
<=
K
<=
5


{\displaystyle 1<=K<=5}

.



Related tasks

   Semiprime
   Category:Prime Numbers


 
' Almost prime
PROGRAM "almostprime"
VERSION "0.0002"
 
DECLARE FUNCTION Entry()
INTERNAL FUNCTION KPrime(n%%, k%%)
 
FUNCTION Entry()
  FOR k@@ = 1 TO 5
    PRINT "k ="; k@@; ":";
    i%% = 2
    c%% = 0
    DO WHILE c%% < 10
      IFT KPrime(i%%, k@@) THEN
        PRINT FORMAT$(" ###", i%%);
        INC c%%
      END IF
      INC i%%
    LOOP
    PRINT
  NEXT k@@
END FUNCTION
 
FUNCTION KPrime(n%%, k%%)
  f%% = 0
  FOR i%% = 2 TO n%%
    DO WHILE n%% MOD i%% = 0
      IF f%% = k%% THEN RETURN $$FALSE
      INC f%%
      n%% = n%% \ i%%
    LOOP
  NEXT i%%
  RETURN f%% = k%%
END FUNCTION
 
END PROGRAM
 