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


 
REM Almost prime
FOR K = 1 TO 5
  S$ = STR$(K)
  S$ = LTRIM$(S$)
  S$ = "k = " + S$
  S$ = S$ + ":"
  PRINT S$;
  I = 2
  C = 0
  WHILE C < 10
    AN = I
    GOSUB CHECKKPRIME:
    IF ISKPRIME <> 0 THEN
      PRINT I;
      C = C + 1
    ENDIF
    I = I + 1
  WEND
  PRINT
NEXT K
END
 
CHECKKPRIME:
REM Check if N (AN) is a K prime (result: ISKPRIME)
F = 0
J = 2
LOOPFOR:  
  ANMODJ = AN MOD J
  LOOPWHILE:
    IF ANMODJ <> 0 THEN AFTERWHILE:
    IF F = K THEN FEQK:
    F = F + 1
    AN = AN / J
    ANMODJ = AN MOD J
    GOTO LOOPWHILE:
  AFTERWHILE: 
  J = J + 1
  IF J <= AN THEN LOOPFOR:
IF F = K THEN
  ISKPRIME = -1
ELSE
  ISKPRIME = 0
ENDIF
RETURN
FEQK:
ISKPRIME = 0
RETURN
 