Paul's solution (slightly modified):
n = 1 is a solution since 1^1 + 1 = 2 which is prime and 2^2 + 1 = 5 which is prime.
Let us consider n>1.
Clearly, when n is odd - x^n + 1 is even, and therefore not prime.
Now for odd values of n:
x^n + 1 is divisible by x+1 when n is odd, so the expression n^n + 1 has a factor (n+1) when n is odd. For example, 5^5 + 1 is divisible by 6. So no odd n is a solution.
But if n is even and has an odd factor f, then we can write n = kf, and (kf)^(kf) + 1 = ((kf)^k)^f + 1 which by the same logic is divisible by (kf)^k + 1. For example, 6^6 + 1 = 36^3 + 1 is divisible by 37. So the only plausible values of n are those with no odd factors -- powers of 2.
But wait, there's more! Suppose n = 2^p where p has an odd factor f. Then n = 2^(kf) and n^n + 1 = (2^fk)^(2^fk) = ((2^k)^(2^fk))^f + 1 which therefore has 2^(k*2^kf) + 1 as a factor. for example, 8 = 2^3 (k=1, f=3) so 8^8 + 1 is divisible by 2^(2^3) + 1 = 257.
So the only possible cases are those where n = 2^(2^k), or where p = 0 which recovers the n=1 solution above.
Almost done. For a full solution, both n and 2n must show this property. Now, if n is 2^k, then 2n = 2^(k+1), but it must also be the case that their exponents are both powers of two. Since exponents differ by 1, we need powers of two that are adjacent. 1 and 2 are the only such, so n = 2^1 is the only potential solution that obeys all of the criteria. And indeed, 2^2 + 1 = 5 is prime and 4^4 + 1 = 257 is also prime.
So the complete list of allowed n is {1, 2}
|