# All integer solutions to diophantine equation: $x^2+p y^2=z^2$?

I would like to find all integer solutions to the Diophantine equation $$x^2+p y^2=z^2$$ where $p\ge2$ is a given prime number. Also prove that my (probably parametric similar to Pythagorean triples $x=a^2-b^2,\ y=2ab,\ z=a^2+b^2$) solution gives all of the.

I tried to move $x^2$ to the right hand side and write $py^2=(z-x)(z+x)$. then assume two cases: (1) $\ \ p|z-x$ , (2) $\ p|z+x$. then I wrote some conditional relation depending on $y$. but I am not satisfied with that. Any help would be appreciated?

• What is your conditional relation on $y$ that you are not satisfied with? And what is your propably parametric solution, and why are you not sure whether it is parametric or not? – flawr Aug 1 '15 at 11:17

This is no different from the Pythagorean case. To classify integer solutions, look instead for rational solutions of $$x^2+py^2=1$$ Thus we want rational points on an ellipse. One solution is $P =(-1,0)$. Stereographically project from that point (that is, given a point $(0,h)$ we extend the line connecting it to P and find its intersection with the ellipse). Elementatry algebra shows that that the point on the ellipse we find this way is rational if and only if h is rational. Explicitly, we get the solution $$\left(\frac{1-ph^2}{1+ph^2},\frac{2h}{1+ph^2}\right)$$ Clearing denominators and letting $h=\frac ab$ we get the general solution $$\left(b^2-pa^2,2ab,b^2+pa^2\right)$$ By construction, this gives all rational solutions up to an integer multiplier. As a commenter( WillJagy) correctly remarked, this method can generate solutions with common factors which must then be canceled to obtain primitive solutions.
• stereographic projection does give all rational solutions, but you still need to check the possible gcd. When $p=5,$ your recipe does not give $2^2 + 5 \cdot 1^2 = 3^2.$ The recipe does give the imprimitive $(-4,2,6)$ with $a=1,b=1$ so $\gcd(a,b) = 1.$ – Will Jagy Aug 1 '15 at 19:35
$$py^2=z^2-x^2=(z+x)(z-x)$$ $p$ is an odd prime, then it divides one of the factors. Then,WLOG: $$\dfrac{z+x}{p}=g^{2-t}a^2$$ $$z-x=g^tb^2$$ This yields $$\pm z=\dfrac{pg^{2-t}a^2+g^tb^2}{2}$$ $$\pm x=\dfrac{pg^{2-t}a^2-g^tb^2}{2}$$ $$\pm y=gab$$ Where $a,b,g$ are all integers.