Checking for some small natural numbers $n$, I found out that $2^n-7$ is a perfect square for $n=3,4,5,7,15$. How can we find all of the numbers $n$ for which $2^n-7$ is a perfect square?
What I tried: For $n=1,2$ there is no $x$ to satisfy the equality. For $n=3$ we have an answer $x=1$ so suppose $n>3$. If $n>3$ then $8|2^n$ so $2^n\equiv0\bmod8$.
We also know that for every $x$, $x^2\equiv0,1,4\bmod 8$. so $x^2+7\equiv 7,0,3\bmod8$ and we had $x^2+7=2^n$ so $x^2+7\equiv0\bmod8$ and this only holds when $x\equiv 3,5\bmod8$.
So the answers for $n>3$ should all be on the form of: $x=8m\pm3$. We can also say: $x^2+7=2^n$ so $x^2-1=2^n-8=8(2^{n-3}-1)$ so $(x-1)(x+1)=8(2^{n-3}-1)$.
I don't know where to go from here. I would appreciate any help.
Edit: Apparently this equation is called the Ramanujan–Nagell equation. I found this pdf in another question but I can't understand it. I would appreciate a good elementary proof (if there is any).
2026-04-22 21:48:54.1776894534