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


 
let kprime(n: i32, k: i32): bool =
  let (p,f) = (2, 0)
  let (n,_,f) = loop (n, p, f) while f < k && p*p <= n do
    let (n,f) = loop (n, f) while 0 == n % p do
      (n/p, f+1)
    in (n, p+1, f)
  in f + (if n > 1 then 1 else 0) == k
 
let main(m: i32): [][]i32 =
  let f k =
    let ps = replicate 10 0
    let (_,_,ps) = loop (i,c,ps) = (2,0,ps) while c < 10 do
      if kprime(i,k) then
        unsafe let ps[c] = i
               in (i+1, c+1, ps)
      else (i+1, c, ps)
    in ps
  in map f (1...m)
 