TITLE: Solving: $3^m-2=n^2$
QUESTION [10 upvotes]: Solve $3^m-2=n^2$ for positive pairs of integers $(n,m)$.

My try:
$3^m-6=n^2-4\implies 3(3^{m-1}-2)=(n+2)(n-2)\implies 3=n+2\ or\ 3=n-2$ so we got $n=\pm 5 , \pm 1$. Used $\pm$ as we have $n^2$.
Putting $n=\pm 5 , \pm 1$ gives $m=3,1$ respectively. We kick out negative ones as problem ask for positive ones only.
But how do I prove that $n+2=3$ not something like multiples of $3$ and similar for $n-2$. More precisely something like the following:
$n+2=3d$, $n-2=k$ and $dk=3^{m-1}-2$.
Please help.

REPLY [3 votes]: If $m=3k$, then the equation is $n^2 = (3^k)^3 -2$.  I put the elliptic curve $y^2=x^3-2$ into SAGE.  The only integral point is $(x,y) = (3,5)$ which corresponds to the the solution $m=3, n=5$.
If $m=3k+1$, then multiply through by $9$ to get $(3n)^2 = (3^{k+1})^3 - 18.$  I put the curve $y^2 = x^3-18$ into SAGE.  The only integral point is $(x,y) = (3,3)$, which corresponds to the solution $m=1, n=1$.
If $m=3k+2$, then multiply through by $81$ to get $(9n)^2 = (3^{k+2})^3 - 182.$  I put the curve $y^2 = x^3 - 182$ into SAGE and there are no integral points.
So there are only the two solutions to the equation.  I don't see a more elementary way to do this.