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
    use iso_fortran_env, only: output_unit
    implicit none
 
    integer :: i, c, k
 
    do k = 1, 5
        write(output_unit,'(A3,x,I0,x,A1,x)', advance="no") "k =", k, ":"
        i = 2
        c = 0
        do
            if (c >= 10) exit
 
            if (kprime(i, k)) then
                write(output_unit,'(I0,x)', advance="no") i
                c = c + 1
            end if
            i = i + 1
        end do
        write(output_unit,*)
    end do
contains
    pure function kprime(n, k)
        integer, intent(in) :: n, k
        logical             :: kprime
        integer             :: p, f, i
 
        kprime = .false.
 
        f = 0
        i = n
 
        do p = 2, n
            do
                if (modulo(i, p) /= 0) exit
 
                if (f == k) return
                f = f + 1
                i = i / p
            end do
        end do
 
        kprime = f==k
    end function kprime
end program almost_prime
 