# Diophantine: $px^2+2=y^2$ where $p\in \mathbb{P}$

Solve the Diophantine Equation: $px^2+2=y^2$, where $p$ is a prime number and $x,y$ integers.

I tried this for ages but didn't get anywhere, but I don't know any advanced machinery since I am only in high school. I would prefer a characterization of solutions or a proof that there exist infinitely many.

• Obviously if $2$ is not a quadratic residue $\pmod{p}$, i.e. if $p\equiv 3,5\pmod{8}$, there are no solutions. – Jack D'Aurizio Aug 12 '14 at 23:13
• Also a similar reasoning shows that all prime factors of $x \equiv \pm 1 \pmod 8$ so $x^2 \equiv 1 \pmod 8$. This forces $p \equiv -1 \pmod 8$. – Sandeep Silwal Aug 12 '14 at 23:14
• No, even assuming $p\equiv 7\pmod{8}$ the existence of a solution (then an infinite number of solution, since we have a Pell equation) depends on the length of the period of the continued fraction of $\sqrt{p}$. If it is even, ok, otherwise, no. – Jack D'Aurizio Aug 12 '14 at 23:23
• Yes, since $\sqrt{23}=[4;1,3,1,8,1,3,1,8,\ldots]$ the convergent $[4;1]=\frac{5}{1}$ gives the least solution $5^2-23\cdot 1^2=2$. – Jack D'Aurizio Aug 12 '14 at 23:36
• Why are everyone talking exclusively about odd primes? $2\cdot 7^2 + 2 = 10^2$ – Arthur Aug 12 '14 at 23:53

In the Wikipedia article related to Pell'equations, you can see (in the paragraph "Transformations") that Legendre proved that the Pell's equation $$x^2 - py^2 = 2$$ has an integer solution (hence an infinite number of integer solutions) for any prime $p\equiv -1\pmod{8}$. As shown in the comments, this is a necessary condition.

• Thought it was Lagrange, couldn't find it anyway. – Will Jagy Aug 13 '14 at 2:52
• It is just the last paragraph of the Wikipedia page. – Jack D'Aurizio Aug 13 '14 at 4:04
• I see what you mean; I was looking before you posted this answer. – Will Jagy Aug 13 '14 at 4:08

There is a particular method of doing continued fractions for quadratic irrationals, due to Gauss and Lagrange, I give a fair amount of detail at https://mathoverflow.net/questions/22811/upper-bound-of-period-length-of-continued-fraction-representation-of-very-compos/23014#23014

Since $2$ is squarefree and small in absolute value, this method shows, quickly, whether there is a solution to $x^2 - n y^2 = 2.$ I told the program to print out the values of $x,y$ that accomplish it. Here are the first few for primes $n \equiv 7 \pmod 8$:

 3^2 - 7 * 1^2 = 2
5^2 - 23 * 1^2 = 2
39^2 - 31 * 7^2 = 2
7^2 - 47 * 1^2 = 2
59^2 - 71 * 7^2 = 2
9^2 - 79 * 1^2 = 2
477^2 - 103 * 47^2 = 2
2175^2 - 127 * 193^2 = 2
41571^2 - 151 * 3383^2 = 2
13^2 - 167 * 1^2 = 2
2999^2 - 191 * 217^2 = 2
127539^2 - 199 * 9041^2 = 2
15^2 - 223 * 1^2 = 2
2489^2 - 239 * 161^2 = 2
373^2 - 263 * 23^2 = 2
340551^2 - 271 * 20687^2 = 2
4109^2 - 311 * 233^2 = 2


Let's see, it is a theorem of Lagrange that all numbers $w$ that are properly represented ($\gcd(x,y)=1$) by $x^2 - n y^2$ with $|w| < \sqrt n$ occur as first coefficients in the cycle of that form, essentially the result of finding continued fraction convergents for $\sqrt n,$ call a convergent $p/q,$ and checking the values of $p^2 - n q^2.$ If you do have a quadratic irrational, the advantage of the cycle method for computer is: (I) no decimal accuracy required, at all, and (II) no cycle detection needed. Here is most of the output for prime 199:

jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$./Pell 199 0 form 1 28 -3 delta -9 1 form -3 26 10 delta 2 2 form 10 14 -15 delta -1 3 form -15 16 9 delta 2 4 form 9 20 -11 delta -2 5 form -11 24 5 delta 5 6 form 5 26 -6 delta -4 7 form -6 22 13 delta 1 8 form 13 4 -15 delta -1 9 form -15 26 2 delta 13 10 form 2 26 -15 delta -1 11 form -15 4 13 delta 1 12 form 13 22 -6 delta -4 13 form -6 26 5 delta 5 14 form 5 24 -11 delta -2 15 form -11 20 9 delta 2 16 form 9 16 -15 delta -1 17 form -15 14 10 delta 2 18 form 10 26 -3 delta -9 19 form -3 28 1 delta 28 20 form 1 28 -3 disc 796 Automorph, written on right of Gram matrix: 123075134 3459240297 1153080099 32409317906 Pell automorph 16266196520 229462939701 1153080099 16266196520 Pell unit 16266196520^2 - 199 * 1153080099^2 = 1 ========================================= 2 127539^2 - 199 * 9041^2 = 2 ========================================= 199 199 jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$