# Missing pattern in solvable negative Pell equation

Considering the negative Pell equation $$x^2 - Dy^2 = -1$$, I know that a necessary condition for solvability is that $$D = a^2 + b^2$$, with $$a,b$$ positive integers.

If I fix $$b = 1$$, NPE is solvable for whatever positive integer value of $$a$$;

If I fix $$b = 2$$, NPE is solvable for $$a$$ being an odd integer;

If I fix $$b = 3$$, NPE is solvable for $$a =$$ $$\{1, 2, 7, 8, 10, 11, 16, 17, 19, 20, 22, ...\}$$, so it seems the is no pattern; same thing if fix $$b = 4$$, then $$a =$$ $$\{1, 5, 7, 9, 11, 13, 15, 21, 25, 29, 31, 33, ...\}$$, so no pattern again, and so on for greater values of $$b$$

Do you know why is that for $$b > 2$$ ? Is it possible to find a pattern in those cases?

There is a pattern, but not one you can see just by looking at the values of $$a$$.

Theorem. For a positive nonsquare integer $$D$$, the equation $$x^2 - Dy^2 = -1$$ has a solution in integers if and only if the continued fraction expansion of $$\sqrt{D}$$ has an odd period.

That theorem gives you a pattern. Maybe it's not what you wanted, but we can't expect simple answers to all simple-sounding questions.

It turns out that we can write down a simple general rule for $$\sqrt{a^2+1}$$ and simple rules for $$\sqrt{a^2+4}$$ depending on the parity of $$a$$, but in higher cases things get more complicated.

For $$a \geq 1$$, $$\sqrt{a^2+1} = [a,2a,2a,2a,2a,\ldots] = [a, \overline{2a}],$$ which has period $$1$$.

For odd $$a \geq 3$$, $$\sqrt{a^2+4} = [a,\overline{(a-1)/2,1,1,(a-1)/2,2a}],$$ which has period $$5$$, while for even $$a \geq 2$$, $$\sqrt{a^2+4} = [a,\overline{a/2,2a}],$$ which has period $$2$$.

The periods for $$\sqrt{a^2+9}$$ when $$a \geq 1$$ (and $$a \not= 4$$, so $$\sqrt{a^2+9}$$ is irrational) look erratic: starting with $$a = 1$$ and skipping $$a = 4$$, the periods are $$1, 5, 2, 4, 6, 7, 7, 2, 15, 3, 8, 6, 8, 8, 9, \ldots$$, so you can see that there's not a simple rule here for even vs. odd periods.

Be thankful that there is a nice rule at all when $$D = a^2+1$$.

There has been recent work on densities of (squarefree) $$D$$ for which $$x^2 - Dy^2 = -1$$ is solvable: see https://arxiv.org/abs/2201.13424.

• Kap once asked this of his student, I think Rotman: prime $p \equiv 1 \pmod 4,$ set $p = a^2 + b^2$ with $a$ the odd one. Then $x^2 - p y^2$ integrally represents $a.$ Rotman gave a proof. Not sure if I have it in writing anywhere. Let me check Kap's students at genealogy genealogy.math.ndsu.nodak.edu/id.php?id=833 Commented Mar 27, 2023 at 0:25
• @WillJagy this result when $D = p$ is a prime that is $1 \bmod 4$ is "well known". Let $x + y\sqrt{p} > 1$ be the least unit in $\mathbf Z[\sqrt{p}]$ greater than $1$ with norm $1$. Then $x$ and $y$ are positive integers. You can show $x$ is odd and $y$ is even from the condition $p\equiv 1 \bmod 4$. From $p(y/2)^2 = (x^2 - 1)/4 = (x+1)/2 \cdot (x-1)/2$, one can obtain an equation $m^2 - pn^2 = \pm 1$ where $1 < m < x$. The minimality of $x+y\sqrt{p}$ then implies $m+n\sqrt{p}$ has norm $-1$, so $m^2 - pn^2 = -1$ in $\mathbf Z$.
– KCd
Commented Mar 27, 2023 at 1:12