By Fermat's Little Theorem, the number x = (2^{p−1} − 1)/p is always an integer if p is an odd prime. For what values of p is x a perfect square?

Suppose (2^{p−1} − 1)/p = a^{2} is a perfect square.

Then 2^{p−1} − 1 = (2^{(p−1)/2} + 1)(2^{(p−1)/2} − 1) = pa^{2}.

The parenthesized terms differ by 2 and are odd; hence they are relatively prime.^{ }

The prime factorization of pa^{2} is p^{c}p_{1}^{2c1}p_{2}^{2c2}...p_{r}^{2cr}, where c is odd.

Hence one parenthesized term is equal to p^{c}s^{2} and the other is equal to t^{2}, for some integers s and t.

Suppose 2^{(p−1)/2} + 1 = t^{2}.

Since t^{2} is odd, let t = 2u + 1, so that 2^{(p−1)/2} + 1 = 4u^{2} + 4u + 1.

Hence 2^{(p−1)/2} = 4u(u + 1).

Since one of u and u + 1 is odd, their product can be a power of 2 only if u = 1, so that (p − 1)/2 = 3, and p = 7.^{ }

Now suppose 2^{(p−1)/2} − 1 = t^{2} = 4u^{2} + 4u + 1.

Then 2^{(p−1)/2} = 2(2u^{2} + 2u + 1).

But 2u^{2} + 2u + 1 is odd, and can be a power of 2 only if it is equal to 1 (when u = 0), so that (p − 1)/2 = 1, and p = 3.

Therefore, the only values of p for which (2^{p−1} − 1)/p is a perfect square are 3 and 7.

Source: Recreations in the Theory of Numbers, by Albert H. Beiler. Chapter VI.