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


 
PROGRAM ALMOST_PRIME
 
!
! for rosettacode.org
!
 
!$INTEGER
 
PROCEDURE KPRIME(N,K->KP)
  LOCAL P,F
  FOR P=2 TO 999 DO
      EXIT IF NOT((F<K) AND (P*P<=N))
      WHILE (N MOD P)=0 DO
         N/=P
         F+=1
      END WHILE
  END FOR
  KP=(F-(N>1)=K)
END PROCEDURE
 
BEGIN
  PRINT(CHR$(12);)  !CLS
  FOR K=1 TO 5 DO
     PRINT("k =";K;":";)
     C=0
     FOR I=2 TO 999 DO
        EXIT IF NOT(C<10)
        KPRIME(I,K->KP)
        IF KP THEN
            PRINT(I;)
            C+=1
        END IF
     END FOR
     PRINT
  END FOR
END PROGRAM
 