For the purpose of this challenge, a Prime Power of a Prime
(PPP) is defined as a number that can be defined as a prime number
to the power of a prime number. For example, 9 is a PPP because it
can be represented as 3^2. 81 on the other hand is not a PPP
because it can only be represented as 3^4, and 4 is not prime. The
first few PPPs are: 4, 8, 9, 25, 27, 32, 49, 121, 125, 128, 169,
243, 289, 343… This is OEIS sequence A053810
あなたのタスク:
入力整数nに対して、n番目のPPP(1-indexedまたは0-indexed)のいずれかを返す/出力するプログラムまたは関数を記述します。
入力:
任意の合理的な方法で受け取った0〜1,000の整数。
出力:
入力によって示されたインデックスのPPP。
テストケース:
これらは1でインデックス付けされているので、プログラムが0でインデックス付けされた入力を受け取った場合、指定された入力-1に対して同じ出力が到着するはずです。
3 -> 9
6 -> 32
9 -> 125
得点:
This code-golf,lowest score in bytes wins!
ベストアンサー
05AB1E, 9 bytes
µNÓʒĀ}p»½
µ # while counter_variable != input:
N # push iteration counter e.g. 125
Ó # get prime exponents -> [0, 0, 3]
ʒĀ} # filter out zeros -> [3]
p # is prime? -> [1]
» # join with newlines: we use » instead of J
# so that [0,1] is not interpreted as truthy -> 1
½ # if 1, increment counter_variable