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


void setup() {
  for (int i = 1; i <= 5; i++) {
    int count = 0;
    print("k = " + i + ": ");
    int n = 2;
    while (count < 10) {
      if (isAlmostPrime(i, n)) {
        count++;
        print(n + " ");
      }
      n++;
    }
    println();
  }
}
 
boolean isAlmostPrime(int k, int n) {
  if (countPrimeFactors(n) == k) {
    return true;
  } else {
    return false;
  }
}
 
int countPrimeFactors(int n) {
  int count = 0;
  int i = 2;
  while (n > 1) {
    if (n % i == 0) {
      n /= i;
      count++;
    } else {
      i++;
    }
  }
  return count;
}