If you've ever learned about primes in math class, you've probably have had to, at one point, determine if a number is prime. You've probably messed up while you were still learning them, for example, mistaking 39 for a prime. Well, not to worry, as 39 is a semiprime, i.e., that it is the product of two primes.
Similarly, we can define a k-almost prime as being the product of k prime numbers. For example, 40 is the 4th 4-almost prime; 40 = 5*2*2*2, the product of 4 factors.
Your task is to write a program/function that accepts two integers n and k as input and output/return the nth k-almost prime number. This is a code-golf, so the shortest program in bytes wins.
n, k => output n, 1 => the nth prime number 1, 1 => 2 3, 1 => 5 1, 2 => 4 3, 2 => 9 5, 3 => 27
You have to generate the primes yourself by any means other than a simple closed form, if such a closed form exists.
fin terms of
f[n,1]is correct, since the lists of almost-primes contain odd numbers (e.g. the last two examples, which are not expressible as the product of a power of two and a prime). (And it also says that
f[n,1] == 2*f[n,1].) \$\endgroup\$