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


include "cowgol.coh";
 
sub kprime(n: uint8, k: uint8): (kp: uint8) is
    var p: uint8 := 2;
    var f: uint8 := 0;
    while f < k and p*p <= n loop
        while 0 == n % p loop
            n := n / p;
            f := f + 1;
        end loop;
        p := p + 1;
    end loop;
    if n > 1 then
        f := f + 1;
    end if;
    if f == k then
        kp := 1;
    else
        kp := 0;
    end if;
end sub;
 
var k: uint8 := 1;
while k <= 5 loop
    print("k = ");
    print_i8(k);
    print(":");
 
    var i: uint8 := 2;
    var c: uint8 := 0;
    while c < 10 loop
        if kprime(i,k) != 0 then
            print(" ");
            print_i8(i);
            c := c + 1;
        end if;
        i := i + 1;
    end loop;
    print_nl();
    k := k + 1;
end loop;