I am trying to find the integer solutions to the equation $x^2-y^2-n=0$.
Effectively, I am trying to find when the difference of two perfect squares is $n$
I have tried using a modified Newton's method to find the nearest point where the equation reaches parity; however, it ends up finding non-integer solutions. I am wondering if there is a way to factor/find all the integer solutions to this equation.
For my algorithm, taking the square root is prohibitively costly and I am trying to avoid using it.
Thanks for the help!
Given $x^2-y^2-n=0\implies y^2+n=x^2\quad$ if $n$ is a perfect square, we have the equation for the Pythagorean theorem where $A^2+B^2=C^2$. The B-value can be any multiple of $4$ so $n=(4z)^2, z\in\mathbb{N}$. There are infinite solutions. Finding them requires a square root but all values of $\sqrt{n}$ are known beforehand so there are always values of $x,y$ to be found in a finite search.
Let's begin with a form of Euclid's formula $F(m,k)$ where $\quad A=m^2-k^2\quad B=2mk\quad C=m^2+k^2.\quad$ We can find $m,k$ by solving $B$ for $k$ and test a finite number of m-values to see which yield integers.
\begin{equation} B=2mk\implies k=\frac{B}{2m}\qquad\text{for}\qquad \bigg\lfloor \frac{1+\sqrt{2B+1}}{2}\bigg\rfloor \le m \le \frac{B}{2} \end{equation} The lower limit ensures $m>k$ and the upper limit ensures $k\ge 1$ $$B=44\implies\quad \bigg\lfloor \frac{1+\sqrt{88+1}}{2}\bigg\rfloor =5 \le m \le \frac{44}{2}=22\\\land \quad m\in\{11,22\}\implies k\in\{2,1\}$$
$$F(11,2)=(117,44,125)\qquad\qquad F(22,1)=(483,44,485)$$
Alternatively, you can just find a list of triples and translate them to fit your equation. For instance, here are examples of triples $A,B,C$ translated to $y,n,x$.
$3,4,5\rightarrow 3,16,5\quad 15,8,17\rightarrow 15,64,17\quad 5,12,13\rightarrow 5,144,13\quad 35,16,37\rightarrow 35,256,37$