TITLE: When is $2^x+3^y$ a perfect square?
QUESTION [10 upvotes]: If $x$ and $y$ are positive integers, then when is $2^x+3^y$ a perfect square?

I tried this question a lot but failed. I tried dividing cases into when $x,y$ are even/odd, but still have no idea what to do when they are both odd. I tried looking into when is  $2^x+3^y$ is of the form $6k+1$ and so on .. but couldn't succeed. Can anyone help?

REPLY [3 votes]: Let $2^x+3^y=k^2$.
mod $3$ gives $x=2m$ for some $m\in\mathbb Z^+$, since $(-1)^x\equiv k^2\pmod {3}$ and since $2$ (i.e. $-1$) is not a quadratic residue mod $3$.
More generally, $\left(\frac{-1}{p}\right)=1\iff p\equiv 1\pmod {4}$, where $p$ is an odd prime and $\left(\frac{a}{b}\right)$ is the Legendre symbol.
Thus $4^m+3^y=k^2$.
So $(-1)^y\equiv k^2\pmod {4}$, but $\left(\frac{-1}{4}\right)=-1$. So $y=2n$ for some $n\in\mathbb Z^+$.
Thus $(2^{m})^2+(3^n)^2=k^2$.
Hence $(2^m,3^n,k)$ is a Pythagorean triple. Moreover, it is primitive, because $(2^m,3^n)=1$, which means:
$$\begin{cases}2^m=2ab\\3^n=a^2-b^2\\k=a^2+b^2\end{cases},$$
where exactly one of $a,b$ is odd.
This implies $(a,b)=(2^i,2^j)$ for some $i,j\in\mathbb Z^+$.
But exactly one of $a,b$ is odd (as I said before), and also $a>b\iff 2^i>2^j$.
Thus $j=0$ so that $(a,b)=(2^i,1)=(2^{m-1},1)$.
Then $4^{m-1}=3^n+1\iff (2^{m-1}-1)(2^{m-1}+1)=3^n$ so that $2^{m-1}-1$ and $2^{m-1}+1$ are powers of $3$, and because their difference is $2$, it follows that $2^{m-1}-1=1\iff m=2\iff x=4$, and $n=1\iff y=2$, which leads us to the only solution $(x,y)=(4,2)$, which after checking works.

The following is an alternative continuation of my solution using Zsigmondy's theorem.  
We have $4^{m-1}=3^n+1$ ($n$ is odd (check $\pmod 4$ and note that $m-1\ge 1$)), but Zsigmondy's theorem implies: 
$$\exists p\in\mathbb P (p\mid a^n+b^n\wedge p\not\mid a+b), \forall n\ge 2, a>b$$ (with the exception of $(a,b,n)=(2,1,3)$, which won't work here, since in our case $(a,b,n)=(3,1,n)$) so that $a^n+b^n$ has more than one prime divisor for any $n\ge 2, a>b$.  
Thus $n\ge 2$ and $3>1$ lead to a contradiction, which means $n=1\iff y=2$ and $m=2\iff x=4$.
This leads to $(x,y)=(4,2)$ as the only solution, which after checking works.

Yet another way I could've proceeded after seeing that $4^{m-1}=3^n+1$ is Catalan's conjecture (now proved), which tells us that $$\begin{cases}x^a-y^b=1\\x,a,y,b\in\mathbb Z_{>1}\end{cases}\iff (x,a,y,b)=(3,2,2,3)$$

Continuation of André Nicolas solution using Zsigmondy's theorem.
$3^y=2^{s+1}+1$.
Notice that $y\ge 1$ so that $s+1\ge 1$. Applying Zsigmondy's theorem leads to a contradiction whenever $s+1\ge 2$ and $2>1$ except for the exception $s+1=3$, which means either $s+1=1\iff (x,y)=(0,1)$, which doesn't work, or $s+1=3\iff s=2$, giving us the only solution $(x,y)=(4,2)$, which after checking works.
This could've also been solved using Catalan's conjecture (now proved), which I introduced above.
But, of course, the easiest route here is to note that (we have $y\ge 1$ and thus $s+1\ge 1$, but $s+1\neq 1$, so $s+1\ge 2$. Now assume $s+1\ge 2$) $\pmod{4}$ leads to $y=2c$ for some $c\in\mathbb Z^+$ so that $(3^c-1)(3^c+1)=2^{s+1}$ and thus $3^c-1=2\iff c=1\iff y=2$ and thus $s+1=3\iff s=2\iff x=4$.
It follows that $(x,y)=(4,2)$ is the only possible solution and after checking it it works.