<s>[INST] Number of Integer Solutions to $k^2-2016=3^n$ How many pairs of integers (k,n) satisfy the equation 
$k^2-2016=3^n$
The only thing I could think to do was factor out 3^2 from the entire equation to get
$(k/3)^2-224=3^{n-2}$
but that doesn't lead to anything useful. I know that (45, 2) is a solution, but that was from trial and error. Can you show me how to solve this or at least point me in the right direction? Thanks.
 [/INST] Note that $2016=224\times 9$ and $x^2\equiv 0,1 \pmod 4$. If $x^2\equiv 0 \pmod 4$, then $3^n\equiv 0 \pmod 4$, but this is impossible. So it must be $x^2\equiv 1 \pmod 4$. Since $3^{2r+1}\equiv 3 \pmod 4$ and $3^{2r}\equiv 1 \pmod 4$ we deduce that $n$ is even. So, let's say $n=2m$ with $m\ge 0$. On the other hand, since $x^2=2016+9^m$ we get that $3|x$, so we can write $x=3y$. 
Therefore we have the equation $9y^2-2016=9^m$, which is equivalent to $y^2-224=9^{m-1}$. If $m>1$, $9|9^{m-1}$ and thus $9|y^2-224$. Since $224\equiv -1 \pmod 9$, we get that $y^2\equiv -1\pmod 9$, but for $a\in \mathbb{Z}$ we have $a^2\equiv 0,1,4,7 \pmod 9$, so it's impossible to have $y^2\equiv -1 \pmod 9$. Then $m=1$ and so $n=2$. From this we get $k^2=2016+9=2025$, so $k=\pm 45$. 
Hence, all the integer solutions are the pairs $(k,n)=(45,2), (-45,2)$. 
</s>