Skip to main content.

Solution to puzzle 158: Fermat squares

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


Suppose (2p−1 − 1)/p = a2 is a perfect square.
Then 2p−1 − 1 = (2(p−1)/2 + 1)(2(p−1)/2 − 1) = pa2.
The parenthesized terms differ by 2 and are odd; hence they are relatively prime. 
The prime factorization of pa2 is pcp12c1p22c2...pr2cr, where c is odd.
Hence one parenthesized term is equal to pcs2 and the other is equal to t2, for some integers s and t.

Suppose 2(p−1)/2 + 1 = t2.
Since t2 is odd, let t = 2u + 1, so that 2(p−1)/2 + 1 = 4u2 + 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 = t2 = 4u2 + 4u + 1.
Then 2(p−1)/2 = 2(2u2 + 2u + 1).
But 2u2 + 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 (2p−1 − 1)/p is a perfect square are 3 and 7.

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

Back to top