Given a number n, print the nth prime Fermat number, where the Fermat numbers are of the form 22k+1. This code should theoretically work for any n (i.e. don't hardcode it), although it is not expected to terminate for n > 4. (It should not return 4294967297 for n=5, as 4294967297 is not a prime number.)
Do note that while all Fermat primes are of the form 22n+1, not all numbers of the form 22n+1 are prime. The goal of this challenge is to return the n-th prime.
Test cases
0 -> 3
1 -> 5
2 -> 17
3 -> 257
4 -> 65537
Rules
- Standard loopholes are disallowed.
- 0-indexing and 1-indexing are both acceptable.
- This is code-golf, lowest byte-count wins.
Related: Constructible n-gons
2^(2^n) + 1
, wheren
is the input? This lines up with your test cases (which we know are already prime, so there's no need to check). And you don't expect the program to work where n > 4 (and n=5 is the first non-prime). \$\endgroup\$n=1:4
. All fermat primes are of the form2^2^n+1
, but that does not mean that all numbers of the form2^2^n+1
are actually prime. This is the case forn=1:4
, but not forn=5
for example. \$\endgroup\$n
and the output must be of the form2^(2^n)+1
. If you use different variables for the input and the exponent then some confusion might be reduced. It might also help if you explicitly state that "n=5 doesn't need to output in reasonable time, but it must not output 4294967297" \$\endgroup\$