Diophantine equation $x^2 -y^2 = n$ Is there a method to find how much integer solutions $(x,y)$ has the diophantine equation
$$x^2-y^2=n,$$ for a given $n \in \mathbb{Z}$?
 A: Yes.
$x^2-y^2=(x+y)(x-y)$.  Let $z=x+y,w=x-y$, then your question is almost the same as asking for the number of solutions to $zw=n$.  The only catch is that $z$ and $w$ must be either both even or both odd, because $z-w=2y$.  So if $n$ is twice an odd number, there are no solutions.
If $n$ is odd, let $$n=p_1^{r_1}p_2^{r_2}...p_k^{r_k}.$$  $z$ is a factor of $n$, so $$z=\pm p_1^{a_1}p_2^{a_2}...p_k^{a_k}\\0\leq a_i\leq r_i$$.  How many ways can you choose the set of $\{a_1,a_2,...,a_k\}$?
$w$ is then just $n/z$.
For example, if $n=3^25^1=9\times5=45$, let $z=3^15^0=3$, and $w=n/z=15$.  Then $z-w=2y=-12$, so $y=-6$ and $z+w=2x=18$,so $x=9$.  That gives the solution $45=9^2-(-6)^2$.
The number of solutions is a function of $r_1,...,r_k$, and not a function of $p_i$ at all.
If $n=4m$, then do the same thing to $m$.  After finding $z$ and $w$ with $zw=m$, double both $z$ and $w$ before finding $x$ and $y$
A: Both $x − y$ and $x + y$ should be factors of $n$. Therefore, we get an upper bound. Now, we only need to count how many of those factorizations into two factors result in the factors having same parity (modulo 2).
If $n$ is odd, then the answer is $4$ times the number of distinct factors of $n$. Else if, $n = 2^k m$ where $2 \nmid m$, then the answer should be $k - 1$ times the number of distinct factors of $m$.
