Find the sum of the all possible values of $n$ such that $5\cdot 3^m+4=n^2$ $5\cdot 3^m+4=n^2$.
Find the sum of all possible values of $n$. 
It is an question from prermo 2016 west Bengal exam. I try to do it using theory of congruence. But I can't proceed. I am disappointed, how do I find the sum? Can anybody can help me? 
Thank you 
 A: We can move the $4$ over to the RHS and factor it as a difference of squares:
$$5\cdot 3^m = (n-2)(n+2)$$
Note that the two factors on the right differ by $4$, so they cannot be both divisible by $3$. This means that $3^m|n-2$ or $3^m|n+2$. In addition, the other factor must divide $5$, so it is either $1$ or $5$. 
Case 1: $n-2 = 1$.
In this case, we get that $n=3$ and that $m=0$, a valid solution.
Case 2: $n+2 = 5$.
This yields the same result as case 1.
Case 3: $n-2 = 5$.
This yields $n=7, m=2$, also resulting in a valid solution. Thus, the answer is the sum of all possible values of $n$, or $10$.
(Note: I'm assuming you meant all positive values of $n$. Otherwise, since the equation is satisfied for $-n$ iff it is satisfied for $n$, the sum is trivially $0$, and it is a bad trick question.)
A: Given equation can be re written as 
$$5\cdot 3^m = (n-2)(n+2)$$
let $\gcd((n-2),(n+2))=d$ So $d|(n+2)-(n-2)=4$ Thus possible values for $d$ is $1,2,4$. As $d|(5\cdot 3^m), d=1$ as $5\cdot 3^m$ is odd for all values of $m$. This ensure that $5\cdot 3^m$ can only be factored as $5$ and $3^m$ , not as $5\cdot 3^k$ and $ 3^{(m-k)}$ where $1 \le k \le m$ as on that case $\gcd(5\cdot3^k,3^{(m-k)})=3^r$ where $r=min(k,m-k)$ , but that is not possible. So either $n-2=5$ and $n+2= 3^m$ or $n+2=5$ and $n-2= 3^m$. From first case we get $(m,n)=(2,7)$ and from second case we get $(m,n)=(0,3)$
