# When is $2^n -7$ a perfect square?

This came up while solving another ENT problem. I want to ask when is: $$2^n -7 \text{ where } n\geq 3$$ a perfect square? Specifically, I also wanted to know what would be the solutions when $n$ is odd? How should I solve this?

I can check that $n=3, 4, 7$ are solutions but cannot find more. As it is of the form $4k+1$, it doesn't help as well.

• You might as well add $n=4$ to the list because it's easy to show that's the last time it's happening for an even number. Jan 30, 2015 at 14:22
• Works for n in {3, 4, 5, 7, 15} and possibly more Jan 30, 2015 at 14:26
• Possible duplicate, but it appears that this question has been received much more positively... Better make the other question a duplicate of this one -> I've voted to do so. Jan 30, 2015 at 18:29
• @barto Heh :D ${}$ Jan 30, 2015 at 18:32

The equation $$2^n-7=x^2$$ is called the Ramanujan–Nagell equation. It has been conjectured by Ramanujan and proven by Nagell, and later others, that the only solutions are $n=3,4,5,7$ and $15$. Here are two proofs:
I believe all proofs make use of unique factorization in the ring of integers of $\mathbb{Q}(\sqrt{-7})$.
So, there were just a few solutions to $2^n = x^2 + 7.$
The other side is, for $n \geq 3,$ there is always a solution to $$2^n = x^2 + 7 y^2$$ with $\gcd(x,y)=1.$ Proof by induction; as I recall, to keep the gcd thing, we demand that $x \equiv y \equiv 1 \pmod 4$ for all $n,$ which sometimes requires $x$ or $y$ or both to be negative. Note that it would not be impressive if we allowed $x,y$ even, because doubling both $x,y$ just adds $2$ to $n.$