Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

This chapter gives the general theory and useful algorithms to find positive integer solutions (x, y) to general Pell’s equation (4.1.1), where D is a nonsquare positive integer, and N a nonzero integer. There are five good methods for solving the general Pell’s equation:

  1. 1.

    The Lagrange–Matthews–Mollin (LMM) method;

  2. 2.

    Brute-force search (which is good only if | N | is small and the minimal positive solution to Pell’s resolvent is small);

  3. 3.

    Use of quadratic rings;

  4. 4.

    The cyclic method;

  5. 5.

    Lagrange’s system of reductions.

Of these five, we will present only the first three, with two versions for the third one. These two last algorithms are comparable in terms of effectiveness. For the cyclic method see [67] and for the Lagrange’s system of reductions see [52] or [142].

4.1 General Theory

In a memoir of 1768, Lagrange gave a recursive method for solving the equation

$$\displaystyle{ x^{2} - Dy^{2} = N }$$
(4.1.1)

with \(\gcd (x,y) = 1\), where D > 1 is not a perfect square and N ≠ 0, thereby reducing the problem to the situation where \(\vert N\vert <\sqrt{D}\), in which case the positive solutions (x, y) are found among the pairs (p n , q n ), with p n q n a convergent of the simple continued fraction for \(\sqrt{ D}\).

It does not seem to be widely known that Lagrange also gave another algorithm in a memoir of 1770, which may be regarded as a generalization of the well-known method of solving Pell’s equation and negative Pell’s equation presented in Section 3.3 by using the simple continued fraction for \(\sqrt{ D}\) (see [196]). Quadratic Reciprocity (see [21, 185] and [179] for various applications)

In what follows we will call (4.1.1) the general Pell’s equation. First we will present the general method of finding the solutions to this equation following the presentation in [56, 112, 125, 126, 151] and [161].

Like in Section 3.5 we will consider the Pell’s resolvent

$$\displaystyle{ u^{2} - Dv^{2} = 1. }$$
(4.1.2)

Let (u n , v n ) n ≥ 0 be the general solution to the equation (4.1.2) given in Theorem 3.2.1. Assume that equation (4.1.1) is solvable and let (x, y) be one of its solutions. Then

$$\displaystyle{(u_{n} + v_{n}\sqrt{D})(x + y\sqrt{D}) = (u_{n}x + v_{n}yD) + (u_{n}y + v_{n}x)\sqrt{D}}$$

and

$$\displaystyle{(u_{n}x + v_{n}yD)^{2} - D(u_{ n}y + v_{n}x)^{2} = (x^{2} - Dy^{2})(u_{ n}^{2} - Dv_{ n}^{2}) = N \cdot 1 = N.}$$

It follows that (x n , y n ) n ≥ 0, where

$$\displaystyle{ x_{n} = xu_{n} + Dyv_{n}\quad \text{and}\quad y_{n} = yu_{n} + xv_{n} }$$
(4.1.3)

satisfies the general Pell’s equation. Hence every initial solution to (4.1.1) generates its own family of infinitely many solutions.

This method of generating solutions is called the multiplication principle.

The main problem here is to decide whether or not two different initial solutions generate different general solutions described above.

We say that solution (x n , y n ) n ≥ 0 given by (4.1.3) is associated with the solution (u n , v n ) n ≥ 0. The set of all solutions associated with each other forms a class of solutions to (4.1.1).

Next we will show a way to decide whether the two given solutions (x, y) and (x′, y′) belong to the same class or not. In fact, by using the method given in Theorem 3.5.2 it is easy to see that the necessary and sufficient condition for these two solutions to be associated with each other is that the numbers

$$\displaystyle{\frac{xx' - Dyy'} {N} \quad \text{and}\quad \frac{yx' - xy'} {N} }$$

are both integers.

Let K be the class consisting of the solutions (x n , y n ) n ≥ 0 defined by (4.1.3). Then (x n , −y n ) n ≥ 0 also constitutes a class, denoted by \(\overline{K}\). The classes K and \(\overline{K}\) are said to be conjugates of each other. Conjugate classes are in general distinct, but may sometimes coincide; in the latter case we speak of ambiguous classes.

Among all the solutions (x, y) in a given class K we now choose a solution (x , y ) in the following way: let y be the least nonnegative value of y which occurs in K. If K is not ambiguous, then the number x is also uniquely determined, for the solution (−x , y ) belongs to the conjugate class \(\overline{K}\). If K is ambiguous, then we get a uniquely determined x by prescribing that x  ≥ 0. The solution (x , y ) defined in this way is said to be the fundamental solution of the class.

In the fundamental solution, the number | x  | has the least value which is possible for | x | when (x, y) belongs to K. The case x  = 0 can occur when the class is ambiguous, and similarly for the case y  = 0.

If N = ±1, there is only one class and it is ambiguous.

Suppose now that N is positive.

Theorem 4.1.1.

If (x,y) is the fundamental solution of the class K of the equation (4.1.1) and if (u 1 ,v 1 ) is the fundamental solution of the Pell’s resolvent (4.1.2) , then the following inequalities hold:

$$\displaystyle\begin{array}{rcl} 0 \leq \vert x\vert \leq \sqrt{\frac{(u_{1 } + 1)N} {2}} & &{}\end{array}$$
(4.1.4)
$$\displaystyle\begin{array}{rcl} 0 <y \leq \frac{v_{1}} {\sqrt{2(u_{1 } + 1)}}\sqrt{N}.& &{}\end{array}$$
(4.1.5)

Proof.

If inequalities (4.1.4) and (4.1.5) are true for a class K, they are also true for the conjugate class \(\overline{K}\). Thus we may assume that y is positive.

It is clear that

$$\displaystyle{ xu_{1} - Dyv_{1} = xu_{1} -\sqrt{(x^{2 } - N)(u_{1 }^{2 } - 1)}> 0. }$$
(4.1.6)

Consider the solution \((xu_{1} - Dyv_{1},yu_{1} - xv_{1})\) which belongs to the same class as (x, y). Since (x, y) is the fundamental solution of the class and since by (4.1.6) xu 1Dyv 1 is positive, we must have xu 1Dyv 1 ≥ x. From this inequality it follows that

$$\displaystyle{x^{2}(u_{ 1} - 1)^{2} \geq D^{2}y^{2}v_{ 1}^{2} = (x^{2} - N)(u_{ 1}^{2} - 1)}$$

or

$$\displaystyle{\frac{u_{1} - 1} {u_{1} + 1} \geq 1 - \frac{N} {x^{2}}}$$

and finally \(x^{2} \leq \frac{1} {2}(u_{1} + 1)N\). This proves inequality (4.1.4) and it is easily seen that (4.1.4) implies (4.1.5). □ 

Suppose next that N < 0 and call (4.1.1) the general negative Pell’s equation. With a proof similar to the one in Theorem 4.1.1 we have

Theorem 4.1.2.

If (x,y) is the fundamental solution of the class K of the general negative Pell’s equation and if (u 1 ,v 1 ) is the fundamental solution of the Pell’s resolvent (4.1.2), then the following inequalities hold:

$$\displaystyle\begin{array}{rcl} 0 \leq \vert x\vert \leq \sqrt{\frac{(u_{1 } - 1)\vert N\vert } {2}} & &{}\end{array}$$
(4.1.7)
$$\displaystyle\begin{array}{rcl} 0 <y \leq \frac{v_{1}} {\sqrt{2(u_{1 } - 1)}}\sqrt{\vert N\vert }.& &{}\end{array}$$
(4.1.8)

From Theorems 4.1.1 and 4.1.2 we deduce

Theorem 4.1.3.

If D is a nonsquare positive integer and N is a nonzero integer, then the equation (4.1.1) has a finite number of classes of solutions. The fundamental solutions of all the classes can be found after a finite number of trials by means of the inequalities (4.1.4), (4.1.5) and (4.1.7) , (4.1.8) . If (x ,y ) is the fundamental solution of the class K, then all the solutions in K are given by (x n ,y n ) n≥0 , where

$$\displaystyle{x_{n} = x^{{\ast}}u_{ n} + Dy^{{\ast}}v_{ n}\quad \text{and}\quad y_{n} = y^{{\ast}}u_{ n} + x^{{\ast}}v_{ n}}$$

and (u n ,v n ) n≥0 represents the general solution of Pell’s resolvent including ± 1, if necessary.

Remark.

The upper bounds for fundamental solutions that generate the classes of solutions of general Pell’s equation (4.1.1) found in Theorems 4.1.1 and 4.1.2 can still be improved. In [76] it is shown that

$$\displaystyle{0 \leq \vert x\vert \leq \sqrt{\varepsilon \vert N\vert },\quad 0 <y \leq \sqrt{\frac{\varepsilon \vert N\vert } {D}} }$$

where \(\varepsilon = u_{1} + v_{1}\sqrt{D}\).

In the private communication (L. Panaitopol, personal communication, December 2001) the following better upper bounds are mentioned

$$\displaystyle{0 \leq \vert x\vert \leq \sqrt{\frac{\vert N\vert u_{1 } + N} {2}},\quad 0 <y \leq \sqrt{\frac{\vert N\vert u_{1 } - N} {2D}}.}$$

In the above delimitations (u 1, v 1) denotes the fundamental solution to the Pell’s equation (4.1.2).

We denote by k(D, N) the number of classes of solutions of the equation (4.1.1), and by \(\mathcal{K}(D,N)\) the set of the fundamental solutions of all classes.

Theorem 4.1.4.

Let p be a prime. Then each of the general Pell’s equations

$$\displaystyle{ x^{2} - Dy^{2} = \pm p }$$
(4.1.9)

has at most one solution (x,y) in which x and y satisfy the inequalities (4.1.4) and (4.1.5) , or (4.1.7) and (4.1.8) , respectively, provided that x ≥ 0.

If the equation (4.1.9) is solvable, then it has one or two solutions satisfying the above conditions, according as the prime p divides 2D or not.

Proof.

Suppose that (x, y) and (x 1, y 1) are two solutions of (4.1.9) satisfying the conditions in the first part of Theorem 4.1.4. Thus the numbers x, y, x 1 and y 1 are nonnegative.

Eliminating D between relations

$$\displaystyle{ x^{2} - Dy^{2} = \pm p,\quad x_{ 1}^{2} - Dy_{ 1}^{2} = \pm p }$$
(4.1.10)

yields \(x^{2}y_{1}^{2} - x_{1}^{2}y^{2} = \pm p(y_{1}^{2} - y^{2})\). Thus \(xy_{1} \equiv x_{1}y\pmod p\).

Furthermore, from (4.1.10) we obtain

$$\displaystyle{(xx_{1} \mp Dyy_{1})^{2} - D(xy_{ 1} \mp x_{1}y)^{2} = p^{2}.}$$

In the equation

$$\displaystyle{ \left (\frac{xx_{1} \mp Dyy_{1}} {p} \right )^{2} - D\left (\frac{xy_{1} \mp x_{1}y} {p} \right )^{2} = 1 }$$
(4.1.11)

let us choose the sign such that the congruence \(xy_{1} \equiv \pm x_{1}y\pmod p\) is satisfied. Then the two squares on the left-hand side are integers. If xy 1x 1 y ≠ 0, from (4.1.11) we conclude that

$$\displaystyle{ \vert xy_{1} \mp x_{1}y\vert \geq v_{1}p. }$$
(4.1.12)

On the other hand, by applying inequalities (4.1.4) and (4.1.5), or (4.1.7) and (4.1.8), respectively, we obtain | xy 1x 1 y | < v 1 p, which is contrary to (4.1.12). The remaining case is xy 1x 1 y = 0, which is obviously possible only for x = x 1 and y = y 1. Thus the first part of Theorem 4.1.4.

Consequently, there are at most two classes of solutions. Suppose that (x, y) and (x, −y) are two solutions which satisfy inequalities (4.1.4) and (4.1.5), or (4.1.7) and (4.1.8), respectively. These solutions are associated if and only if p divides the two numbers 2xy and \(x^{2} + Dy^{2} = 2Dy^{2} \pm p\). Since y cannot be divisible by p, the numbers 2x and 2D are divisible by p. But if 2D is divisible by p, then so is 2x. Thus, the necessary and sufficient condition for (x, y) and (x, −y) to belong to the same class is that 2D is a multiple of p. Thus proves the second part of the theorem. □ 

The following example illustrates how the method described in Theorem 4.1.4 can be applied.

Consider the equation \(x^{2} - 2y^{2} = 119\). The fundamental solution of its Pell’s resolvent \(u^{2} - 2v^{2} = 1\) is (3, 2). The following solutions of our equation satisfy inequalities (4.1.4) and (4.1.5): (11, 1), (−11, 1), (13, 5), (−13, 5). It is not difficult to show that these numbers are all fundamental solutions in different classes. Thus the number of classes is four but only solutions (11,1) and (13,5) satisfy Theorem 4.1.4. The form of the integer N is very important. For instance, in the paper [174] are considered the equations \(x^{2} - Dy^{2} = \pm c(2^{31} - 1)\).

We will now present an example which illustrates how one can use Theorem 4.1.4. We will now rely on the result in our paper [16]. In [37] the following question is posed: Does the Diophantine equation

$$\displaystyle{ 8x^{2} - y^{2} = 7 }$$
(4.1.13)

have infinitely many solutions in positive integers?

Recently, in the paper [114] the more general equation \(ax^{2} - by^{2} = c\) is considered. It is shown that if ab is not a square and the above equation has a positive integer solution (x 0, y 0), then it has infinitely many positive integer solutions. This property is a direct consequence of the multiplication principle. In the paper [143] a simple criterion for solving both equations \(x^{2} - Dy^{2} = c\) and \(x^{2} - Dy^{2} = -c\) is presented.

In what follows, we will find all solutions to the equation (4.1.13). We can write the equation (4.1.13) in the following equivalent form: \(y^{2} - 8x^{2} = -7\). This is a special case of (4.1.9). In our case, p = 7 and p does not divide 2D = 16. Applying Theorem 4.1.4 we deduce that the equation (4.1.13) has two classes of solutions and these are generated by (−1, 1) and (1, 1). The Pell’s resolvent \(u^{2} - 8v^{2} = 1\) has the fundamental solution (u 1, v 1) = (3, 1) and its general solution (u n , v n ) n ≥ 0 is given by (see formulas (3.2.6)):

$$\displaystyle{ \left \{\begin{array}{l} u_{n} = \frac{1} {2}\left [\left (3 + \sqrt{8}\right )^{n} + \left (3 -\sqrt{8}\right )^{n}\right ] \\ v_{n} = \frac{1} {2\sqrt{8}}\left [\left (3 + \sqrt{8}\right )^{n} -\left (3 -\sqrt{8}\right )^{n}\right ] \\ \end{array} \right. }$$
(4.1.14)

Applying Theorem 4.1.3 it follows that all solutions to the equation (4.1.13) are given by (x n , y n ) n ≥ 0 and (x n , y n ) n ≥ 0, where

$$\displaystyle{\left \{\begin{array}{l} x_{n} = u_{n} + v_{n} \\ y_{n} = u_{n} + 8v_{n} \end{array} \right.\quad \text{and}\quad \left \{\begin{array}{l} x'_{n} = u_{n} - v_{n} \\ y'_{n} = -u_{n} + 8v_{n} \end{array} \right.}$$

and (u n , v n ) n ≥ 0 is defined in (4.1.14). We obtain two classes of solutions:

$$\displaystyle{(x,y) = (1,1),\ (4,11),\ (23,65),\ (134,379),\ldots }$$

and

$$\displaystyle{(x',y') = (2,5),\ (11,31),\ (64,181),\ (373,1055),\ldots }$$

respectively.

Remark.

We will describe now the set of rational solutions to the Pell’s equation \(u^{2} - Dv^{2} = 1\). A family of such solutions was given in Remark 4 in Section 3.2

For fixed positive integers m and n consider the general Pell’s equation \(x^{2} - Dy^{2} = (mn)^{2}\). Consider the set of all its integral solutions (x, y) satisfying n | x and m | y and let \(\mathcal{S}_{m,n}\) be the set of all pairs \(\left (\frac{x_{1}} {m}, \frac{y_{1}} {n} \right )\), where x = x 1 n, y = y 1 m. The set of all rational solutions to \(u^{2} - Dv^{2} = 1\) is then given by \(\mathcal{S} =\bigcup _{m,n\geq 1}\mathcal{S}_{m,n}\).

The following interesting result was proved in the paper [72].

Theorem 4.1.5.

Let \(D = a^{2} + (2b)^{2}\) , with \(a,b \in \mathbb{Z}\) . If D is a prime, the following hold:

  1. 1)

    The equation \(x^{2} - Dy^{2} = a\) is solvable.

  2. 2)

    The equation \(x^{2} - Dy^{2} = 4b\) is solvable.

If D is not prime, then both 1) and 2) can fail. For instance \(221 = 10^{2} + 11^{2} = 5^{2} + 14^{2}\), but for a = ±5 or ± 11 the equation \(x^{2} - 221y^{2} = a\) has no solution mod 13, while for b = ±5 or ± 7 the equation \(x^{2} - 221y^{2} = 4b\) has no solution mod 17.

4.2 Solvability of General Pell’s Equation

Disregarding any time considerations, Theorem 4.1.1 may be used to determine whether any general Pell equation is solvable or not. Following the reference [204], let consider the general Pell equation \(x^{2} - 43y^{2} = 35\). According to Theorem 4.1.1, if it is solvable, then any of its fundamental solutions (x, y) must lie within the following bounds: \(0 <\vert x\vert \leq \left [\sqrt{35(3482 + 1)/2}\right ] = 246\) and \(0 <v \leq \left [532\sqrt{35/(2(3482 + 1))}\right ] = 37\), where (3482, 532) is the fundamental solution to the Pell’s resolvent \(u^{2} - 43v^{2} = 1\). After checking all 9102 possible combinations of (x, y) we see that the equation \(x^{2} - 43y^{2} = 35\) is not solvable.

With regards to computational efficiency, the question of solvability for the considered example is no match for modern computers. But, what happens when N gets large? Clearly, \(\sqrt{\frac{(u_{1 } - 1)\vert N\vert } {2}} \rightarrow \infty\), as N → ±. Thus, Theorem 4.1.1, though a nice tool, does not allow one to efficiently decide if a particular general Pell equation is solvable. In the reference [204] is mentioned the equation \(x^{2} - 313y^{2} = 172635965\) and the fact that, using the actual computation force, we need about 69806785 years to prove the unsolvability, following the method provided by Theorem 4.1.1. Thus, in this particular example, with N = 172635965 relatively small, using the approach in Theorem 4.1.1 will take a considerable amount of time. The question of solvability of the general Pell’s equation can be formulated into two problems:

Pell Decision Problem (PDP). Given a positive integer D ≥ 2 which is not a perfect square, and an integer N, is there an efficient means to decide if the equation (4.1.1) is solvable?

In some situations PDP can be reduced to the case when D is a prime (see for instance Theorem 3.6.2).

Pell Search Problem (PSP). Assuming that the equation (4.1.1) is solvable, can we find all fundamental solutions in the Pell classes in a reasonable amount of time?

Notice that a general criterion for solvability is, in effect, a solution to a PDP. In this section we address the problem of finding a general criterion for solvability of general Pell equation and give a partial solution. Most of the tests that we develop throughout this section are based on the reference [204] and do not rely on integer factorization. However, a few of the implementations based on these results will rely heavily on the efficiency of integer factorization, which is likely no more efficient than tests based on the Pell class approach.

4.2.1 PDP and the Square Polynomial Problem

In what follows we will show that the PDP is equivalent to the problem of deciding whether or not a particular second degree polynomial with integer coefficients has a square integer value. In this respect we formulate the following concrete problem:

Square Polynomial Decision Problem (SPDP). Does there exist an algorithm that, for any odd prime p and \(N \in \mathbb{Z}\) with \(\gcd (N,p) = 1\) decides if there is for some a with \(N \equiv a^{2}\pmod p\) and \(n \in \mathbb{Z}\) such that \(pn^{2} - 2an + \frac{a^{2} - N} {p}\) is a square?

The SPDP and the PDP for specific D and N may be formulated in terms of arithmetical functions. Let p be a prime, \(N \in \mathbb{Z}\), with \(\left (\frac{N} {p} \right ) = 1\) and consider the equation \(x^{2} - py^{2} = N\). Since \(\left (\frac{N} {p} \right ) = 1\) we have \(a^{2} \equiv N\pmod p\) for some positive integer a. Note that, the Tonelli–Shanks algorithm, assuming the Generalized Riemann Hypothesis, efficiently find an integer a such that \(a^{2} \equiv N\pmod p\) (see [159, pp. 110–115]).

Following the reference [204], define the functions

$$\displaystyle{\phi (p,N) = \left \{\begin{array}{rl} 1&\text{if}\ pn^{2} - 2an + \frac{a^{2} - N} {p} \ \text{is a square for some} \\ &\text{integers}\ n\ \text{and}\ a\ \text{with }a^{2} \equiv N\pmod p \\ - 1&\text{otherwise} \end{array} \right.}$$

and

$$\displaystyle{\psi (p,N) = \left \{\begin{array}{rl} 1&\text{if }x^{2} - py^{2} = N\text{ is solvable} \\ - 1&\text{otherwise}. \end{array} \right.}$$

Clearly, in the definition of ϕ(p, N) we can assume that \(a \in \mathbb{Z}_{p}\).

Now, we have the proper terminology to prove the following result.

Theorem 4.2.1.

Let p be an odd prime and \(N \in \mathbb{Z}\) with \(\left (\frac{N} {p} \right ) = 1\) . Then, ψ(p,N) = 1 if and only if ϕ(p,N) = 1.

Proof.

If ψ(p, N) = 1, then we have \(u^{2} - pm^{2} = N\) for some integers u, m. Observe that \(y^{2} \equiv N\pmod p\). To prove ϕ(p, N) = 1 we must show that there is an integer n such that \(pn^{2} - 2un + \frac{u^{2} - N} {p}\) is a square. But, we have \(\frac{u^{2} - N} {p} = m^{2}\), hence we choose n = 0. Therefore ϕ(p, N) = 1.

Suppose ϕ(p, N) = 1. That is, there are integers n, m and \(u \in \mathbb{Z}_{p}\) such that \(u^{2} \equiv N\pmod p\) and \(pn^{2} - 2un + \frac{u^{2} - N} {p} = m^{2}\). The last relation is equivalent to \((u + pn)^{2} - pm^{2} = N\), so the pair (u + pn, m) is a solution to the general Pell’s equation \(x^{2} - py^{2} = N\). Thus, the relation ψ(p, N) = 1 holds. □ 

The result in Theorem 4.2.1 proves that SPDP is equivalent to PDP.

4.2.2 The Legendre Test

The Legendre symbol and the Quadratic Reciprocity Law provide the first test for the solvability of general Pell’s equation.

Theorem 4.2.2.

If \(\left (\frac{N} {p} \right ) = -1\) then \(\psi (p,N) = -1\) , that is \(x^{2} - py^{2} = N\) is not solvable.

Proof.

If the equation \(x^{2} - py^{2} = N\) were solvable, then \(u^{2} - pv^{2} = N\) for some integers u and v. Therefore, \(u^{2} - N = pv^{2}\), hence \(u^{2} \equiv N\pmod p\), implying \(\left (\frac{N} {p} \right ) = 1\), contradicting our assumption. □ 

Corollary 4.2.3.

If \(\left (\frac{N} {p} \right ) = 1\) and \(\left (\frac{M} {p} \right ) = -1\) , then the equation

$$\displaystyle{x^{2} - py^{2} = MN}$$

is not solvable.

Example 1.

Consider the general Pell’s equation \(x^{2} - 17y^{2} = -46\). Using the properties of the Legendre symbol, we have

$$\displaystyle\begin{array}{rcl} & \left (\frac{-46} {17} \right ) = \left (\frac{-1} {17} \right )\left (\frac{46} {17}\right ) = \left (\frac{12} {17}\right ) = \left ( \frac{4} {17}\right )\left ( \frac{3} {17}\right )& {}\\ & = \left ( \frac{3} {17}\right ) = \left (\frac{17} {3} \right ) = \left (\frac{2} {3}\right ) = -1, & {}\\ \end{array}$$

hence, according to Theorem 4.2.2, the considered equation is not solvable.

4.2.3 Legendre Unsolvability Tests

This subsection uses the Quadratic Reciprocity Law and some properties of the Legendre symbol to obtain some tests for the unsolvability of general Pell’s equation.

Theorem 4.2.4.

Let p be an odd prime and N a positive integer. If \(p \equiv 3\pmod 4\) and \(\left (\frac{N} {p} \right ) = 1\) , then the equation \(x^{2} - py^{2} = -N\) is not solvable.

Proof.

If the equation is solvable, then we have \(r^{2} - ps^{2} = -N\), for some integers r, s. It follows \(r^{2} \equiv -N\pmod p\), hence \(\left (\frac{-N} {p} \right ) = 1\). Using the standard properties of the Legendre symbol we get

$$\displaystyle{1 = \left (\frac{-N} {p} \right ) = \left (\frac{-1} {p} \right )\left (\frac{N} {p} \right )}$$

and

$$\displaystyle{\left (\frac{-1} {p} \right ) = \left (\frac{-1} {p} \right ) \cdot 1 = \left (\frac{-1} {p} \right )\left (\frac{N} {p} \right ) = \left (\frac{-N} {p} \right ) = 1.}$$

By the Quadratic Reciprocity Law, this only happens when \(p \equiv 1\pmod 4\), contradicting our assumption. □ 

Example 2.

Consider the equation \(x^{2} - 11y^{2} = -5\). Since (4,1) is a solution to \(x^{2} - 11y^{2} = 5\), we have \(\left ( \frac{5} {11}\right ) = 1\). Since \(11 \equiv 3\pmod 4\), by Theorem 4.2.4, we obtain that the considered equation is not solvable.

The next result is given in [204] and it yields a general test for the unsolvability of a large class of general Pell’s equations.

Theorem 4.2.5.

Let p be a prime, \(p \equiv 3\pmod 4\) , and N = m 2 n with n square free. If \(x^{2} - py^{2} = N\) is solvable, then \(n \equiv 1\pmod 4\) .

Proof.

Suppose that \(n \equiv 3\pmod 4\). Since \(x^{2} - py^{2} = N\) is solvable, there are \(u,v \in \mathbb{Z}\) such that \(u^{2} - pv^{2} = m^{2}n\). We shall collect the following three facts:

  1. (i)

    \(\left (\frac{n} {p}\right ) = 1\).

  2. (ii)

    If q is a prime divisor of n with \(q \equiv 3\pmod 4\), then \(\left (\frac{q} {p}\right ) = -1\).

  3. (iii)

    Let r = | {q:  q | n and q is an odd prime and \(q \equiv 3\pmod 4\}\vert\). Then r is odd.

Since \(u^{2} - pv^{2} = m^{2}n\), we have \(u^{2} - m^{2}n = pv^{2}\). So, \(X^{2} \equiv N\pmod p\) is solvable. Thus, \(\left (\frac{n} {p}\right ) = \left (\frac{m^{2}n} {p} \right ) = 1\). This proves (i).

Now suppose that q is a prime divisor of n. So, n = qn 0 for some \(n_{0} \in \mathbb{Z}\). Thus, \(u^{2} - pv^{2} = qn_{0}\) and so \(X^{2} \equiv pv^{2}\pmod p\) is solvable. So, \(\left (\frac{p} {q}\right ) = \left (\frac{pv^{2}} {q} \right ) = 1\). By the Quadratic Reciprocity Law, we know that, since \(p \equiv q \equiv 3\pmod 4\), \(\left (\frac{p} {q}\right ) = -\left (\frac{q} {p}\right )\). So, \(-\left (\frac{q} {p}\right ) = 1\). This proves (ii).

Let \(n = q_{1}\ldots q_{r} \cdot q_{r+1}\ldots q_{l}\), where \(q_{1} \equiv \ldots \equiv q_{r} \equiv 3\pmod 4\) and \(q_{r+1} \equiv \ldots \equiv q_{l} \equiv 1\pmod 4\). If r is even, then we may arrange these first r primes in pairs as follows: (q 1 ⋅ q 2), (q 3 ⋅ q 4), , (q r−1 ⋅ q r ). Then, for i even with 1 ≤ i ≤ r, \((q_{i-1} \cdot q_{i}) \equiv 9 \equiv 1\pmod 4\). But, then \(n = (q_{1} \cdot q_{2}) \cdot (q_{3} \cdot q_{4})\ldots (q_{r-1} \cdot q_{r}) \cdot q_{r+1}\ldots q_{l} \equiv 1\pmod 4\) contrary to assumption. This proves (iii).

Again let \(n = q_{1}\ldots q_{r}q_{r+1}\ldots q_{l}\), where \(q_{1} \equiv \ldots \equiv q_{r} \equiv 3\pmod 4\) and \(q_{r+1} \equiv \ldots \equiv q_{l} \equiv 1\pmod 4\). Because r is odd, by (ii) we have

$$\displaystyle{\left (\frac{q_{1}} {p} \right )\ldots \left (\frac{q_{r}} {p} \right ) = (-1)\ldots (-1) = (-1)^{r} = -1.}$$

Also,

$$\displaystyle{\left (\frac{q_{r+1}} {p} \right )\ldots \left (\frac{q_{l}} {p} \right ) = 1\ldots 1 = 1^{l-r} = 1.}$$

Therefore, by (i) we obtain

$$\displaystyle\begin{array}{rcl} & 1 = \left (\frac{n} {p}\right ) = \left (\frac{q_{1}\ldots q_{r}q_{r+1}\ldots q_{l}} {p} \right ) & {}\\ & = \left (\frac{q_{1}} {p} \right )\ldots \left (\frac{q_{r}} {p} \right )\left (\frac{q_{r+1}} {p} \right )\ldots \left (\frac{q_{l}} {p} \right ) = (-1)^{r} \cdot 1 = -1,& {}\\ \end{array}$$

a contradiction. □ 

The result in Theorem 4.2.5, when expressed using the contrapositive, yields a nice test for unsolvability. We state this as the following consequence.

Corollary 4.2.6.

Let N = m 2 n with n square free. If p is a prime with \(p \equiv n \equiv 3\pmod 4\) , then the equation \(x^{2} - py^{2} = N\) is not solvable.

The next consequence follows immediately.

Corollary 4.2.7.

If \(p \equiv N \equiv 3\pmod 4\) and \(M \equiv 1\pmod 4\) , then the equation \(x^{2} - py^{2} = MN\) is not solvable.

Example 3.

Consider the equation \(x^{2} - 31y^{2} = 1008\). We have 1008 = 122 ⋅ 7 and \(7 \equiv 3\pmod 4\). Corollary 4.2.6 allows us to conclude that the equation is not solvable.

The next result requires that we know a prime factor ≥ 3 of N.

Theorem 4.2.8.

Let q be an odd prime divisor of N. If the equation \(x^{2} - py^{2} = N\) is solvable, then \(\left (\frac{p} {q}\right ) = 1\) .

Proof.

Assume that \(u^{2} - pv^{2} = N\), for some integers u, v. Because \(N \equiv 0\pmod q\), it follows \(u^{2} \equiv pv^{2}\pmod q\).

Therefore, \(\left (\frac{pv^{2}} {q} \right ) = 1\), hence \(\left (\frac{p} {q}\right ) = 1\). □ 

In the case when we can find an odd prime divisor of N, the contrapositive to Theorem 4.2.8 provides a nice test for unsolvability.

Corollary 4.2.9.

Let q be an odd prime divisor of N. If \(\left (\frac{p} {q}\right ) = -1\) , then the equation \(x^{2} - py^{2} = N\) is not solvable.

Now, we are in position to discuss the solvability of the equation

$$\displaystyle{x^{2} - 313y^{2} = 172635965,}$$

considered at the beginning of this section. Because 5 is a prime divisor of 172635965 and \(\left (\frac{313} {5} \right ) = -1\), we may use Corollary 4.2.9 to conclude the unsolvability of the equation.

Corollary 4.2.10.

Let q be an odd prime divisor of N. If p or \(q \equiv 1\pmod 4\) and \(\left (\frac{q} {p}\right ) = -1\) , then the equation \(x^{2} - py^{2} = N\) is not solvable.

Proof.

Because p or \(q \equiv 1\pmod 4\), we have \(\left (\frac{p} {q}\right ) = \left (\frac{q} {p}\right ) = -1\), and we can use the result in Corollary 4.2.9.

Corollary 4.2.11.

Let N = m 2 n, where n is square free. If p is a prime with \(p \equiv 5\pmod 8\) , and n is even, then the equation \(x^{2} - py^{2} = N\) is not solvable.

Proof.

Suppose that \(u^{2} - pv^{2} = N\), for some integers u, v. It follows \(\left (\frac{N} {p} \right ) = 1\), hence \(\left (\frac{n} {p}\right ) = \left (\frac{m^{2}n} {p} \right ) = 1\). Since n is even, we have n = 2n 0, \(n_{0} \in \mathbb{Z}\), and \(\left (\frac{2n_{0}} {p} \right ) = 1\). Because \(p \equiv 5\pmod 8\), we have \(\left (\frac{2} {p}\right ) = -1\). Therefore, n has a prime factor q such that \(\left (\frac{q} {p}\right ) = -1\). But, n is square free, so q must be odd. Moreover, from \(p \equiv 5\pmod 8\), it follows \(p \equiv 1\pmod 4\) and the conclusion follows from Corollary 4.2.9. □ 

The following application is given in the reference [204].

Example 4.

Consider the equation \(x^{2} - 181y^{2} = 1908360\). We have \(181 \equiv 5\pmod 8\) and 1908360 = 182 ⋅ 5890 with 5890 = 2 ⋅ 5 ⋅ 19 ⋅ 31 even and square free. Applying Corollary 4.2.11, it follows the unsolvability of the equation.

4.2.4 Modulo n Unsolvability Tests

We will describe a simple but useful way to test the unsolvability of general Pell’s equation.

Theorem 4.2.12.

If the equation \(x^{2} - Dy^{2} = N\) is not solvable in \(\mathbb{Z}_{n}\) , for some positive integer n ≥ 2, then it is not solvable in integers.

Proof.

Assume that \(u^{2} - Dv^{2} = N\) for some integers u, v. The remainder upon dividing u 2Dv 2 by n will be the same as the remainder in the division of N by n. Therefore, the equation \(x^{2} - Dy^{2} = N\) is solvable in \(\mathbb{Z}_{n}\). Thus, by the contrapositive, the result follows. □ 

Note that if the equation \(x^{2} - Dy^{2} = N\) is solvable in \(\mathbb{Z}_{n}\) for some positive integer n ≥ 2, then it is not necessarily the case that it is solvable in integers.

Theorem 4.2.13.

Let p be a prime with \(p \equiv 3\pmod 4\) , and N an odd integer. If the equation \(x^{2} - py^{2} = N\) is solvable, then \(N \equiv 1\pmod 4\) .

Proof.

We have a 2 ≡ 0 \(1\pmod 4\), and by direct calculation, we see that \(x^{2} - oy^{2} \equiv x^{2} - 3y^{2} \equiv 0,1,\) or \(2\pmod 4\). Therefore, if \(N \equiv 3\pmod 4\), the equation is not solvable in \(\mathbb{Z}_{4}\), and, by mod 4 test, the equation is not solvable in integers. □ 

Using the same argument, but in \(\mathbb{Z}_{8}\), we can prove the following result.

Theorem 4.2.14.

Let p be a prime with p ≡ 1,3, or \(5\pmod 8\) , and N an integer with \(N \equiv 2\pmod 4\) . Then the equation \(x^{2} - py^{2} = N\) is not solvable.

4.2.5 Extended Multiplication Principle

We now give some tests for the solvability of general Pell’s equation, using an extension of the multiplication principle discussed in Section 4.1.

Extended Multiplication Principle. If \(u^{2} - Dv^{2} = M\) and \(r^{2} - Ds^{2} = N\) , then \((ur \pm Dvs)^{2} - D(us \pm vr)^{2} = MN\) , where the signs + and − correspond.

The above identity is also called the Bhaskara identity, according to the name of the Hindu mathematician mentioned in Section 3.1

We can reformulate this algebraic property as follows: If the general Pell’s equations \(u^{2} - Dv^{2} = M\) and \(r^{2} - Ds^{2} = N\) are solvable, then the equation \(x^{2} - Dy^{2} = MN\) is also solvable.

As an application to the Extended Multiplication Principle, we present an extension of the result involving the negative Pell’s equation, and contained in Theorem 3.6.2.

Theorem 4.2.15.

Let p be a prime with \(p \equiv 1\pmod 4\) . The equation

$$\displaystyle{x^{2} - py^{2} = -N}$$

is solvable if and only if the equation \(x^{2} - py^{2} = N\) is solvable.

Proof.

By Theorem 3.6.2, we know that the negative Pell’s equation

$$\displaystyle{u^{2} - pv^{2} = -1}$$

is solvable. Now, the result directly follows from the Extended Multiplicative Principle. □ 

Remark.

Notice that if we can factor N, say N = N 1 … N s and show, for all i = 1, , s, that the equation \(x^{2} - Dy^{2} = N_{i}\) is solvable, then using successively the Extended Multiplication Principle we obtain that the equation \(x^{2} - Dy^{2} = N\) is solvable.

The converse of the above remark need not hold, as the next example illustrates.

Example 5.

Considering the equation \(x^{2} - 37y^{2} = 192\), we have \(192 = 4^{2} \cdot 12 = 8^{2} \cdot 3\). The equations \(x^{2} - 37y^{2} = 12\) and \(x^{2} - 37y^{2} = 4^{2}\) are clearly solvable, hence according to the Extended Multiplication Principle, it follows the considered equation is solvable. On the other hand, if we use the second factorization of 192, we see that \(x^{2} - 37y^{2} = 3\) is not solvable (apply Theorem 4.1.1 where (u 1, v 1) = (73, 12). Thus, we may not conclude that the unsolvability of \(x^{2} - 37y^{2} = 3\) implies the unsolvability of \(x^{2} - 37y^{2} = 192\).

4.3 An Algorithm for Determining the Fundamental Solutions Based on Simple Continued Fractions (The LMM Method)

We will describe an almost forgotten algorithm due to Lagrange, for deciding the solvability of general Pell’s equation (4.1.1), where gcd(x, y) = 1 and D > 0 is not a perfect square. In the case of solvability, the fundamental solutions are also constructed.

The main purpose of this section is to present a version of Lagrange’s algorithm which uses only the technique of simple continued fractions.

A related algorithm is given in [158] but each of the cases D = 2 or D = 3 and N < 0 needs separate consideration. Also, unlike our algorithm, the approach in [158] requires the calculation of the fundamental solution of Pell’s resolvent.

Lagrange’s algorithm has been rediscovered in [141]. The method there is more complicated than ours, as it uses the language of ideals and semi-simple continued fractions, in addition to that of simple continued fractions.

First we need a result which is an extension of Theorem 172 in [88].

Lemma 4.3.1.

If \(\omega = \frac{P\zeta + R} {Q\zeta + S}\) , where ζ > 1 and P,Q,R,S are integers such that Q > 0, S > 0 and \(PS - QR = \pm 1\) , or S = 0 and \(Q = R = 1\) , then P∕Q is a convergent to ω. Moreover if Q ≠ S > 0, then

$$\displaystyle{\frac{R} {S} = \frac{p_{n-1} + kp_{n}} {q_{n-1} + kq_{n}},\quad k \geq 0.}$$

Also, ζ + k is the (n + 1)-th complete convergent to ω. Here k = 0 if Q > S, while k ≥ 1 if Q < S.

Proof.

In [88] only the case Q > S > 0 is considered. We write

$$\displaystyle{\frac{P} {Q} =\langle a_{0};a_{1},\ldots,a_{n}\rangle = \frac{p_{n}} {q_{n}}}$$

and assume \(PS - QR = (-1)^{n-1}\). Then

$$\displaystyle{p_{n}S - q_{n}R = PS - QR = p_{n}q_{n-1} - p_{n-1}q_{n},}$$

so \(p_{n}(S - q_{n-1}) = q_{n}(R - p_{n-1})\).

Hence \(q_{n}\vert (S - q_{n-1})\). Then from q n  = Q > S > 0 and q n  ≥ q n−1 > 0, we deduce \(\vert S - q_{n-1}\vert <q_{n}\) and hence \(S - q_{n-1} = 0\). Then \(S = q_{n-1}\) and \(R = p_{n-1}\).

Also

$$\displaystyle{\omega = \frac{P\zeta + R} {Q\zeta + S} = \frac{p_{n}\zeta + p_{n-1}} {q_{n}\zeta + q_{n-1}} =\langle a_{0};a_{1},\ldots,a_{n},\zeta \rangle.}$$

If S = 0 and \(Q = R = 1\), then ω = [P, ζ] and \(P/Q = P/1 = p_{0}/q_{0}\).

If Q = S, then \(Q = S = 1\) and \(P - R = \pm 1\). If \(P = R + 1\), then ω = [R, 1, ζ], so \(P/Q = (R + 1)/1 = p_{1}/q_{1}\). If \(P = R - 1\), then \(\omega = [R - 1,1+\zeta ]\) and \(P/Q = (R - 1)/1 = p_{0}/q_{0}\).

If Q < S, then from \(q_{n}\vert (S - q_{n-1})\) and

$$\displaystyle{S - q_{n-1}> Q - q_{n-1} = q_{n} - q_{n-1} \geq 0,}$$

we have \(S - q_{n-1} = kq_{n}\), where k ≥ 1. Then

$$\displaystyle{\omega = \frac{P\zeta + R} {Q\zeta + S} = \frac{p_{n}\zeta + p_{n-1} + kp_{n}} {q_{n}\zeta + q_{n-1} + kq_{n}} = \frac{p_{n}(\zeta +k) + p_{n-1}} {q_{n}(\zeta +k) + q_{n-1}} }$$

and \(\omega =\langle a_{0};a_{1},\ldots,a_{n},\zeta +k\rangle\). □ 

Theorem 4.3.2.

Suppose \(x^{2} - Dy^{2} = N\) is solvable in integers x > 0, y > 0, with gcd (x,y) = 1 and let Q 0 = |N|. Then gcd (Q 0 ,y) = 1. Define P 0 by \(x \equiv -P_{0}y\pmod Q_{0}\) , where \(D \equiv P_{0}^{2}\pmod Q_{0}\) and \(-Q_{0}/2 <P_{0} \leq Q_{0}/2\) .

Let \(\omega = (P_{0} + \sqrt{D})/Q_{0}\) and let \(x = Q_{0}X - P_{0}y\) . Then

  1. (i)

    X∕y is a convergent \(A_{n-1}/B_{n-1}\) of ω if x > 0;

  2. (ii)

    \(Q_{n} = (-1)^{n}N/\vert N\vert\) .

Proof.

With Q 0 = | N | , \(x = Q_{0}X - P_{0}y\) and \(x^{2} - Dy^{2} = N\), we have

$$\displaystyle{P_{0}x + Dy \equiv -P_{0}^{2}y + Dy \equiv (-P_{ 0}^{2} + D)y \equiv 0\pmod Q_{ 0}.}$$

Hence the matrix

$$\displaystyle{\left [\begin{array}{cc} P &R\\ Q & S \end{array} \right ] = \left [\begin{array}{cc} X &\frac{P_{0}x+Dy} {Q_{0}} \\ y & x \end{array} \right ]}$$

has integer entries and determinant \(\Delta = \pm 1\). For

$$\displaystyle\begin{array}{rcl} \Delta & =& Xx -\frac{y(P_{0}x + Dy)} {Q_{0}} {}\\ & =& \frac{(x + P_{0}y)x} {Q_{0}} -\frac{y(P_{0}x + Dy)} {Q_{0}} {}\\ & =& \frac{x^{2} - Dy^{2}} {Q_{0}} = \pm 1. {}\\ \end{array}$$

Also, if \(\zeta = \sqrt{D}\) and \(\omega = (P_{0} + \sqrt{D})/Q_{0}\), it is easy to verify that \(\omega = \frac{P\zeta + R} {Q\zeta + S}\). Then the lemma implies that Xy is a convergent to ω.

Finally, \(x = Q_{0}X - P_{0}y = Q_{0}A_{n-1} - P_{0}B_{n-1} = G_{n-1}\) and

$$\displaystyle{N = x^{2} - Dy^{2} = G_{ n-1}^{2} - DB_{ n-1}^{2} = (-1)^{n}Q_{ 0}Q_{n}.}$$

Hence \(Q_{n} = (-1)^{n}N/\vert N\vert\). □ 

Remark.

The solutions u of \(u^{2} \equiv D\pmod Q_{0}\) come in pairs \(\pm u_{1},\ldots,\pm u_{r}\), where 0 < u i  ≤ Q 0∕2, together with possibly \(u_{r+1} = 0\) and \(u_{r+2} = Q_{0}/2\). Hence we can state the following:

Corollary 4.3.3.

Suppose \(x^{2} - Dy^{2} = N\) is solvable, with x > 0 and y > 0, gcd (x,y) = 1 and Q 0 = |N|. Let \(x \equiv -P_{0}y\pmod Q_{0}\) , where \(P_{0} \equiv \pm u_{i}\pmod Q_{0}\) and \(x = Q_{0}X - P_{0}y\) . Then X∕y is a convergent \(A_{n-1}/B_{n-1}\) of \(\omega _{i} = (u_{i} + \sqrt{D})/Q_{0}\) or \(\omega '_{i} = (-u_{i} + \sqrt{D})/Q_{0}\) and \(Q_{n} = (-1)^{n}N/\vert N\vert\) .

4.3.1 An Algorithm for Solving the General Pell’s Equation (4.1.1)

In view of the Corollary 4.3.3 we know that the primitive solutions to \(x^{2} - Dy^{2} = N\) with y > 0 will be found by considering the continued fraction expansions of both ω i and ω i for 1 ≤ i ≤ r + 2.

One can show that each equivalence class contains solutions (x, y) with x > 0 and y > 0, so the necessary condition \(Q_{n} = (-1)^{n}N/\vert N\vert\) occurs in both ω i and ω i . Hence we need only consider ω i .

Suppose that \(\omega _{i} = (u_{i} + \sqrt{D})/Q_{0} = [a_{0},\ldots,a_{t},\overline{a_{t+1},\ldots,a_{t+l}}]\).

If \(x^{2} - Dy^{2} = N\) is solvable, there are infinitely many solutions and hence Q n  = ±1 holds for ω i for some n in the range \(t + 1 \leq n \leq t + l\). Any such n must have Q n  = 1, as \((P_{n} + \sqrt{D})/Q_{n}\) is reduced for n in this range and so Q n  > 0. Moreover, if l is even, then the condition \((-1)^{n} = N/\vert N\vert\) is preserved.

In addition, there can be at most one such n. For if \(P_{n} = \sqrt{D}\) is reduced, then \(P_{n} = [\sqrt{D}]\) and hence two such occurrences of Q n  = 1 within a period would give a smaller period.

We also remark that l is odd if and only if the fundamental solution of Pell’s equation has norm equal to − 1. Consequently, a solution of \(x^{2} - Dy^{2} = N\) gives rise to a solution of \(x^{2} - Dy^{2} = -N\); indeed we see that if \(t + 1 \leq n \leq t + l\) and k ≥ 1, then \(G_{n+kl-1} + B_{n+kl-1}\sqrt{D} =\eta _{ 0}^{k}(G_{n-1} + B_{n-1}\sqrt{D})\), where η 0 is the fundamental solution of \(x^{2} - Dy^{2} = \pm 1\). Hence \(G_{n+l-1}^{2} - DB_{n+l-1}^{2} = -(G_{n-1}^{2} - DB_{n-1}^{2})\) if \(N(\eta _{0}) = -1\).

Putting these observations together, we have the following:

Theorem 4.3.4.

For 1 ≤ i ≤ r + 2, let

$$\displaystyle{\omega _{i} = (u_{i} + \sqrt{D})/Q_{0} =\langle a_{0},\ldots,a_{t},\overline{a_{t+1},\ldots,a_{t+l}}\rangle.}$$
  1. (a)

    Then a necessary condition for \(x^{2} - Dy^{2} = N\) , gcd (x,y) = 1, to be solvable is that for some i in \(i = 1,\ldots,r + 2\) , we have Q n = 1 for some n in \(t + 1 \leq n \leq t + l\) , where if l is even, then \((-1)^{n}N/\vert N\vert = 1\) .

  2. (b)

    Conversely, suppose for ω i , we have Q n = 1 for some n with \(t + 1 \leq n \leq t + l\) . Then

    1. (i)

      If l is even and \((-1)^{n}N/\vert N\vert = 1\) , then \(x^{2} - Dy^{2} = N\) is solvable and it has solution \(G_{n-1} + B_{n-1}\sqrt{D}\) .

    2. (ii)

      If l is odd, then \(G_{n-1} + B_{n-1}\sqrt{D}\) is a solution of \(x^{2} - Dy^{2} = (-1)^{n}\vert N\vert\) , while \(G_{n+l-1} + B_{n+l-1}\sqrt{D}\) is a solution of \(x^{2} - Dy^{2} = (-1)^{n+1}\vert N\vert\) .

    3. (iii)

      At least one of the \(G_{n-1} + B_{n-1}\sqrt{D}\) with least B n−1 satisfying \(Q_{n} = (-1)^{n}N/\vert N\vert\) , which arise from continued fraction expansions of ω i and ω′ i , is a fundamental solution.

Remarks.

  1. 1)

    Unlike the case of Pell’s equation, Q n  = ±1 can also occur for n < t + 1 and can contribute to a fundamental solution. If N(η) = 1, one sees that to find the fundamental solutions for both \(x^{2} - Dy^{2} = \pm N\), it suffices to examine only the cases Q n  = ±1, n ≤ t + l. However if \(N(\eta ) = -1\), one may have to examine the range \(t + l + 1 \leq n \leq t + 2l\) as well.

  2. 2)

    It can happen that l is even and that \(x^{2} - Dy^{2} = N\) is solvable and has solution \(x \equiv \pm u_{i}y\pmod Q_{0}\), while \(x^{2} - Dy^{2} = -N\) is solvable and has solution \(x \equiv \pm u_{j}y\pmod Q_{0}\), with ij. (Of course, if | N | = p is prime, this cannot happen, as the congruence \(u^{2} \equiv D\pmod p\) has two solutions if p does not divide D and one solution if p divides D.)

An example of this is D = 221, N = 217 (see Example 2 later). Then u 1 = 2, u 2 = 33. Also, l = 6 and \((2 + \sqrt{221})/217\) produces the solution \(-2 + \sqrt{221}\) of \(x^{2} - 221y^{2} = -217\), whereas \((33 -\sqrt{221})/217\) produces the solution \(-179 + 12\sqrt{221}\) of \(x^{2} - 221y^{2} = 217\).

Example 1 (Lagrange).

\(x^{2} - 13y^{2} = \pm 101\).

We find the solutions of \(P_{0}^{2} \equiv 13\pmod 101\) are ± 35.

  1. (a)

    We have \(\frac{35 + \sqrt{13}} {101} = [0,2,1,\overline{1,1,1,1,6}]\).

    $$\displaystyle{\begin{array}{|c|c|c|c|c|c|c|c|c|c|} \hline i & 0 & 1 & 2 & 3 &4& 5 & 6 & 7 & 8\\ \hline P_{ i} & 35 & - 35&11& - 2&3& 1 & 2 & 1 & 3\\ \hline Q_{ i}&101& - 12& 9 & 1 &4& 3 & 3 & 4 & 1 \\ \hline A_{i} & 0 & 1 & 1 & 2 &3& 5 & 8 &13& 86 \\ \hline B_{i}& 1 & 2 & 3 & 5 &8&13&21&34&225 \\ \hline \end{array} }$$

    We observe that \(Q_{3} = Q_{8} = 1\). The period length is odd, so both the equations \(x^{2} - 13y^{2} = \pm 101\) are solvable. With \(G_{n} = Q_{0}A_{n} - P_{0}B_{n}\), we have

    $$\displaystyle\begin{array}{rcl} & G_{2}=101 \cdot 1 - 34 \cdot 3= - 4,\quad x+y\sqrt{13}= - 4+3\sqrt{13},\quad x^{2} - 13y^{2}= - 101;& {}\\ & G_{7}=101 \cdot 13-35 \cdot 34=123,\quad x+y\sqrt{13}=123+34\sqrt{13},\quad x^{2}-13y^{2}=101. & {}\\ \end{array}$$
  2. (b)

    We have \(\frac{-35 + \sqrt{13}} {101} = [-1,1,2,4,\overline{1,1,1,1,6}]\).

    $$\displaystyle{\begin{array}{|c|c|c|c|c|c|c|c|c|c|} \hline i & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \hline P_{ i} & - 35& - 66& 23 & 1 & 3 & 1 & 2 & 1 & 3\\ \hline Q_{ i}& 101 & - 43& 12 & 1 & 4 & 3 & 3 & 4 & 1 \\ \hline A_{i} & - 1 & 0 & - 1& - 4& - 5& - 9& - 14& - 23& - 152 \\ \hline B_{i}& 1 & 1 & 3 & 13 & 16 & 29 & 45 & 74 & 489 \\ \hline \end{array} }$$

    We observe that \(Q_{3} = Q_{8} = 1\). Hence

    $$\displaystyle\begin{array}{rcl} & G_{2}=101 \cdot (-1)-(-35) \cdot 3=4,\ x+y\sqrt{13}=A + 3\sqrt{13},\ x^{2} - 13y^{2} = -101; & {}\\ & G_{7}=101 \cdot (-23)-(-35) \cdot 74=267,\ x+y\sqrt{13}=267+74\sqrt{13},\ x^{2}-13y^{2}=101.& {}\\ \end{array}$$

    Hence \(-4 + 3\sqrt{13}\) and \(123 + 34\sqrt{13}\) are fundamental solutions for the equations \(x^{2} - 13y^{2} = -101\) and \(x^{2} - 13y^{2} = 101\) respectively.

    We have \(\eta = 649 + 180\sqrt{13}\), so the complete solution of \(x^{2} - 13y^{2} = -101\) is given by \(x + y\sqrt{13} = \pm \eta ^{n}(\pm 4 + 3\sqrt{13})\), \(n \in \mathbb{Z}\), while the complete solution of \(x^{2} - 13y^{2} = 101\) is given by \(x + y\sqrt{13} = \pm \eta ^{n}(\pm 123 + 34\sqrt{13})\), \(n \in \mathbb{Z}\).

Example 2.

\(x^{2} - 221y^{2} = \pm 217\).

We find the solutions of \(P_{0}^{2} \equiv 221\pmod 217\) are ± 2 and ± 33.

  1. (a)

    We have \(\frac{2 + \sqrt{221}} {217} = [0,12,\overline{1,6,2,6,1,28}]\).

    $$\displaystyle{\begin{array}{|c|c|c|c|c|c|c|c|c|} \hline i & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7\\ \hline P_{ i} & 2 & - 2&14&11& 13 & 13 & 11 & 14\\ \hline Q_{ i}&217& 1 &25& 4 & 13 & 4 & 25 & 1 \\ \hline A_{i} & 0 & 1 & 1 & 7 & 15 & 97 & 112 & 3233 \\ \hline B_{i}& 1 & 12 &13&90&193&1248&1441&41596 \\ \hline \end{array} }$$

    We observe that \(Q_{1} = Q_{7} = 1\). The period length is even and \((-1)^{7} = -1\). Hence the equation \(x^{2} - 221y^{2} = -217\) is solvable.

    $$\displaystyle\begin{array}{rcl} & G_{0} = 217 \cdot 0 - 2 \cdot 1 = -2,\quad x + y\sqrt{221} = -2 + \sqrt{221},\quad x^{2} - 221y^{2} = -217. & {}\\ & \begin{array}{|c|c|c|c|c|c|c|c|c|c|} \hline i & 0 & 1 & 2 &3&4&5& 6 &7&8 \\ \hline P_{ i}& 33 & - 33&13&5&7&8& 7 &3&4 \\ \hline Q_{ i}&101& - 10& 9 &6&5&3&10&7&9 \\ \hline \end{array} & {}\\ \end{array}$$

    We see that the condition Q n  = 1 does not holds for 3 ≤ n ≤ 8.

4.4 Solving the General Pell’s Equation

4.4.1 The PQa Algorithm for Solving Pell’s and Negative Pell’s Equations

This algorithm is at the heart of all the algorithms to solve Pell’s equations presented here. The input to the algorithms is three integers, D, P 0, Q 0, where D > 0 is not a square, Q 0 > 0, and \(P_{0}^{2} \equiv D\pmod Q_{0}\). Recursively compute, for i ≥ 0

$$\displaystyle\begin{array}{rcl} & a_{i} =\mathrm{ int}(P_{i} + \sqrt{D})/Q_{i},& {}\\ & P_{i+1} = a_{i}Q_{i} - P_{i}, & {}\\ \end{array}$$

and

$$\displaystyle{Q_{i+1} = (D - P_{i+1}^{2})/Q_{ i}.}$$

Also compute G i and B i as follows. Begin with \(G_{-2} = -P_{0}\), \(G_{-1} = Q_{0}\), \(B_{-2} = 1\), and \(B_{-1} = 0\). Then for i ≥ 0, set \(G_{i} = a_{i}G_{i-1} + G_{i-2}\), and set \(B_{i} = a_{i}B_{i-1} + B_{i-2}\). Sometimes one also computes A i as \(A_{-2} = 0\), \(A_{-1} = 1\), and \(A_{i} = a_{i}A_{i-1} + A_{i-2}\) for i ≥ 0. Then \(G_{i} = Q_{0}A_{i} - P_{0}B_{i}\).

Note that \(G_{i}^{2} - DB_{i}^{2} = (-1)^{i+1}Q_{i+1}Q_{0}\). This relation will be important to us because all of the methods of solution we discuss will involve setting Q 0 = | N | , and finding those i so that \((-1)^{i+1}Q_{i+1} = N/\vert N\vert\). Then (G i , B i ) will be a solution to the equation being considered. From a computational viewpoint, also note that, in some sense, G i and B i will typically be large, while Q 0 and Q i+1 will be small. So this equation sometimes allows accurate computation of the left-hand side when numbers on the left-hand side exceed the machine accuracy available. Exactly how far to carry these computations is discussed with each use below.

The sequence a i is the simple continued fraction expansion of \((P_{0} + \sqrt{D})/Q_{0}\), and the A i B i are the convergents to this continued fraction. Each of the sequences P i , Q i , and a i is periodic from some point, although not necessarily the same point for all three. Starting from the right point, the periodic part of the sequence P i is palindromic. For each of the sequences Q i and a i , the periodic part, less the last term, is palindromic.

To solve the equation \(x^{2} - Dy^{2} = \pm 1\), apply the PQa algorithm with P 0 = 0 and Q 0 = 1. There will be a smallest i with a i  = 2a 0, which will also be the smallest i > 0 so that Q i  = 1. There are two cases to consider: this i is odd, or this i is even.

If this i is odd, then the equation \(x^{2} - Dy^{2} = -1\) has solutions. The minimal positive solution is given by \(x = G_{i-1}\), \(y = B_{i-1}\). For any positive integer k, if k is odd then \(x = G_{ki-1}\), \(y = B_{ki-1}\) is a solution to the equation \(x^{2} - Dy^{2} = -1\), and all solutions to this equation with x and y positive are generated this way. If k is an even positive integer, then \(x = G_{ki-1}\), \(y = B_{ki-1}\) is a solution to the equation \(x^{2} - Dy^{2} = 1\), and all solutions to this equation with x and y positive are generated this way. The minimal positive solution to \(x^{2} - Dy^{2} = 1\) is \(x = G_{2i-1}\), \(y = B_{2i-1}\).

If the smallest i so that a i  = 2a 0 is even, then the equation \(x^{2} - Dy^{2} = -1\) does not have any solutions. For any positive integer k, \(x = G_{ki-1}\), \(y = B_{ki-1}\) is a solution to the equation \(x^{2} - Dy^{2} = 1\), and all solutions to this equation with x and y positive are generated this way. In particular, the minimal positive solution to \(x^{2} - Dy^{2} = 1\) is \(x = G_{i-1}\), \(y = B_{i-1}\).

The sequences P j and a j are periodic with period i after the zero-th term, i.e., the first period is P 1 to P i for the sequences P j , and a 1 to a i for the sequence a j . The sequence Q j is periodic starting at the zero-th term, i.e., the first period is Q 0 to Q i−1.

In Sections 3.23.5 and 3.6, respectively, we give several methods to generate all solutions to either Pell’s and negative Pell’s equations once the minimal positive solution is found.

4.4.2 Solving the Special Equations x 2Dy 2 = ±4

In some ways, solutions to the equation \(x^{2} - Dy^{2} = \pm 4\) are more fundamental than solutions to the equation \(x^{2} - Dy^{2} = \pm 1\). The most interesting case is when \(D \equiv 1\pmod 4\), so we cover that first.

When \(D \equiv 1\pmod 4\), apply the PQa algorithm with P 0 = 1 and Q 0 = 2. There will be a smallest i > 0 so that \(a_{i} = 2a_{0} - 1\). This will also be the smallest i > 0 so that Q i  = 2. The minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\) is then \(x = G_{i-1}\), \(y = B_{i-1}\). If i is odd, it will be a solution to the − 4 equation, while if i is even it will be a solution to the + 4 equation and the − 4 equation will not have solutions. Periodicity of the sequences P i , Q i , and a i is similar to that for the ± 1 equation.

If \(D \equiv 0\pmod 4\), then for any solution to \(x^{2} - Dy^{2} = \pm 4\), x must be even. Set \(X = x/2\), set Y = y, and solve \(X^{2} - (D/4)Y ^{2} = \pm 1\). If (X, Y ) is the minimal positive solution to this equation, then x = 2X, y = Y is the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\). Alternatively, one can apply the PQa algorithm with P 0 = 0 and Q 0 = 2. If i is the smallest index so that a i  = 2a 0, then the minimal positive solution is \((G_{i-1},B_{i-1})\).

If D ≡ 2 or \(3\pmod 4\), then by considerations modulo 4 one can that both x and y must be even. Set \(X = x/2\), set \(Y = y/2\), and solve \(X^{2} - DY ^{2} = \pm 1\). If (X, Y ) is the minimal positive solution to this equation, then x = 2X, y = 2Y is the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\). Alternatively, use the PQa algorithm with P 0 = 0 and Q 0 = 1, but set \(G_{-2} = 0\), \(G_{-1} = 2\), \(B_{-2} = 2\), and \(B_{-1} = 0\). If i is the smallest index so that a i  = 2a 0, then the minimal positive solutions is \((G_{i-1},B_{i-1})\).

As with the ± 1 equation, all solutions can be generated from the minimal positive solution. Consider first the equation \(x^{2} - Dy^{2} = 4\). If (x 1, y 1) is the minimal positive solution to this equation, then for the n-th solution we have

$$\displaystyle{ \begin{array}{c} x_{n} + y_{n}\sqrt{D} = \frac{1} {2^{n-1}}(x_{1} + y_{1}\sqrt{D})^{n} \\ \\ x_{n} - y_{n}\sqrt{D} = \frac{1} {2^{n-1}}(x_{1} - y_{1}\sqrt{D})^{n}. \end{array} }$$
(4.4.1)

Therefore

$$\displaystyle{ \begin{array}{c} x_{n} = \left (\frac{x_{1} + y_{1}\sqrt{D}} {2} \right )^{n} + \left (\frac{x_{1} - y_{1}\sqrt{D}} {2} \right )^{n} \\ \\ y_{n} = \frac{1} {\sqrt{D}}\left [\left (\frac{x_{1} + y_{1}\sqrt{D}} {2} \right )^{n} -\left (\frac{x_{1} - y_{1}\sqrt{D}} {2} \right )^{n}\right ]. \end{array} }$$
(4.4.2)

We also have the recursion

$$\displaystyle{ \begin{array}{c} x_{n+1} = \frac{1} {2}(x_{1}x_{n} + Dy_{1}y_{n})\\ \\ y_{n+1} = \frac{1} {2}(y_{1}x_{n} + x_{1}y_{n}) \end{array} }$$
(4.4.3)

The relations (4.4.3) could be written in the following useful matrix form

$$\displaystyle{ \left (\begin{array}{c} x_{n+1} \\ y_{n+1} \end{array} \right ) = \frac{1} {2}\left (\begin{array}{cc} x_{1} & Dy_{1}\\ y_{1 } & x_{1 } \end{array} \right )\left (\begin{array}{c} x_{n} \\ y_{n} \end{array} \right ) }$$
(4.4.4)

from where

$$\displaystyle{ \left (\begin{array}{c} x_{n} \\ y_{n} \end{array} \right ) = \frac{1} {2^{n}}\left (\begin{array}{cc} x_{1} & Dy_{1}\\ y_{1 } & x_{1 } \end{array} \right )^{n}\left (\begin{array}{c} x_{0} \\ y_{0}\end{array} \right ) }$$
(4.4.5)

where (x 0, y 0) = (2, 0) is the trivial solution.

We can express all integer solutions to the positive equation by the following formula

$$\displaystyle{ \frac{1} {2}(u_{n} + v_{n}\sqrt{D}) =\varepsilon _{n}\left (\frac{u_{1} + v_{1}\sqrt{D}} {2} \right )^{n},\quad n \in \mathbb{Z}, }$$
(4.4.6)

where \(\varepsilon _{n}\) is 1 or \(-1\). Indeed, for n > 0 and \(\varepsilon _{n} = 1\) we get all negative solutions. For n > 0 and \(\varepsilon _{n} = -1\) we obtain all solutions (u n , v n ) with u n and v n negative. For n < 0 and \(\varepsilon _{n} = 1\) we have (u n , v n ) with u n  > 0 and v n  < 0, while n < 0 and \(\varepsilon _{n} = -1\) gives u n  < 0 and v n  > 0. The trivial solutions (2, 0) and (−2, 0) are obtained for n = 0.

Formula (4.4.6) captures all symmetries of equation \((u,v) \rightarrow (-u,-v)\), (u, v) → (u, −v), (u, v) → (−u, v). Therefore, in 2D the points (u n , v n ) represents the orbits of the action of the Klein four-group \(\mathbb{Z}_{2} \times \mathbb{Z}_{2}\), i.e., points obtained by the 180 degree rotation, the vertical reflection, and by the horizontal reflection.

Now suppose the equation \(x^{2} - Dy^{2} = -4\) has solutions, let (x 1, y 1) be the minimal positive solution, and define x n , y n by the equation \(x_{n} + y_{n}\sqrt{D} = [(x_{1} + y_{1}\sqrt{D})^{n}]/(2^{n-1})\). Then if n is odd, (x n , y n ) is a solution to the equation \(x^{2} - Dy^{2} = -4\), and if n is even then (x n , y n ) is a solution to the equation \(x^{2} - Dy^{2} = 4\). All positive solutions to these two equations are so generated. The pair (x n , y n ) in (4.4.2) also alternately generates solutions to the + 4 and − 4 equation.

The set of solutions can be summarized as follows.

Theorem 4.4.1.

Let (x 1 ,y 1 ) be the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\) . Then for any solution to \(x^{2} - Dy^{2} = \pm 4\) , there is a choice of signs + and −, and an integer n such that

$$\displaystyle{ \frac{1} {2}(x + y\sqrt{D}) = \pm \left (\frac{x_{1} + y_{1}\sqrt{D}} {2} \right )^{n}. }$$
(4.4.7)

In some ways, the equation \(x^{2} - Dy^{2} = \pm 4\) is more fundamental than the equation \(x^{2} - Dy^{2} = \pm 1\). The numbers 1 and 4 are the only N’s so that, for any D, if you know the minimal positive solution to the equation \(x^{2} - Dy^{2} = \pm N\), you can generate all solutions, and you can do this without solving any other Pell’s equation. Also, if you know the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\), you can generate all the solutions to \(x^{2} - Dy^{2} = \pm 1\). But the converse does not hold. The best that can be said as a converse is that for D not 5 or 12, the solutions to the equation \(x^{2} - Dy^{2} = \pm 4\) can be derived from the intermediate steps when the PQa algorithm is used to solve the equation \(x^{2} - Dy^{2} = \pm 1\).

When \(D \equiv 1\pmod 4\), considerations modulo 4 show that for any solution to \(x^{2} - Dy^{2} = \pm 4\), x and y are both odd or both even. If the minimal positive solution has both x and y even, then all solutions have both x and y even. In this case, every solution to \(x^{2} - Dy^{2} = \pm 1\) is just one-half of a solution to \(x^{2} - Dy^{2} = \pm 4\). If the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\) has both x and y odd, then \(D \equiv 5\pmod 8\), every third solution has x and y even, and all other solutions have x and y odd. In this case, every solution to \(x^{2} - Dy^{2} = \pm 1\) is just one-half of one of the solutions to \(x^{2} - Dy^{2} = \pm 4\) that has both x and y even. When \(D \equiv 1\pmod 4\), the equation \(x^{2} - Dy^{2} = -4\) has solutions if and only if the equation \(x^{2} - Dy^{2} = -1\) has solutions.

When \(D \equiv 0\pmod 4\), considerations modulo 4 show that for any solution to \(x^{2} - Dy^{2} = \pm 4\), x is even. If the minimal positive solution has y even, then all solutions have y even (and x is always even). In this case, every solution to \(x^{2} - Dy^{2} = \pm 1\) is just one-half of a solution to \(x^{2} - Dy^{2} = \pm 4\). If the minimal positive solution to \(x^{2} - Dy^{2} = \pm 4\) has y odd, then every other solution has y even, and every other solution has y odd. In this case, every solution to \(x^{2} - Dy^{2} = \pm 1\) is just one-half of one of the solutions to \(x^{2} - Dy^{2} = \pm 4\) that has x and y both even. When \(D \equiv 0\pmod 4\), it is possible for these to be solutions to \(x^{2} - Dy^{2} = -4\), but not solutions to \(x^{2} - Dy^{2} = 1\). This happens for D = 8, 20, 40, 52 and many more values. Of course, \(x^{2} - Dy^{2} = -1\) never has solutions when \(D \equiv 0\pmod 4\).

When \(D \equiv 2\pmod 4\) or \(D \equiv 3\pmod 4\), all solutions to \(x^{2} - Dy^{2} = \pm 4\) have both x and y even. Every solution to \(x^{2} - Dy^{2} = \pm 1\) is just one-half of a solution to \(x^{2} - Dy^{2} = \pm 4\). The equation \(x^{2} - Dy^{2} = -4\) has solutions if and only if the equation \(x^{2} - Dy^{2} = -1\) has solutions.

The cases \(D \equiv 1\pmod 4\) for D squarefree, and D = 4r for r ≡ 2 or \(3\pmod 4\), r squarefree, are treated in [53]. The material we have presented above is not addressed directly in either [159] or [142]. For example, the proof that the method for solving the equation works in the case \(d \equiv 1\pmod 4\) is not trivially derived from the material in one or both of these sources.

Remark.

Concerning the equation \(x^{2} - Dy^{2} = -4\) the following conjecture is still open: Let p be a prime \(\equiv 1\pmod 4\) and let (x 1 ,y 1 ) be the fundamental solution to the equation \(x^{2} - py^{2} = -4\) . Then \(y_{1}\not\equiv 0\pmod p\) .

This has been verified for all primes p < 2000 with \(p \equiv 5\pmod 8\) and for all primes p < 100000 with \(p \equiv 1\pmod 8\). Also, it has been shown that \(y_{1}\not\equiv 0\pmod p\) if and only if \(B_{\frac{p-1} {4} }\not\equiv 0\pmod p\), where the Bernoulli numbers B n are defined by the series

$$\displaystyle{ \frac{t} {e^{t} - 1} = 1 - \frac{t} {2} +\sum _{ n=1}^{\infty }\frac{(-1)^{n-1}B_{ n}} {(2n)!} t^{2n}.}$$

4.4.3 Structure of Solutions to the General Pell’s Equation

As we have seen in Section 4.1, if (r, s) is a solution to \(x^{2} - Dy^{2} = N\), and (t, u) is any solution to its Pell’s resolvent, then for \(x = rt + Dsu\), \(y = ru + st\), (x, y) is a solution to the equation \(x^{2} - Dy^{2} = N\). This follows from the multiplication principle:

$$\displaystyle{(r^{2} - Ds^{2})(t^{2} - Du^{2}) = (rt + Dsu)^{2} - D(ru + st)^{2}.}$$

This fact can be used to separate solutions to \(x^{2} - Dy^{2} = N\) into equivalence classes. Two solutions (x, y) and (r, s) are equivalent if there is a solution (t, u) to \(t^{2} - Du^{2} = 1\) so that \(x = rt + Dsu\) and \(y = ru + st\).

It may help to view the set of solutions geometrically. If N > 0, then, as an equation in real numbers, \(x^{2} - Dy^{2} = N\) is a hyperbola with the x-axis as its axis, and the y-axis as an axis of symmetry. The asymptotes are the lines \(x \pm y\sqrt{D} = 0\). Let (t, u) be the minimal positive solution to \(x^{2} - Dy^{2} = 1\). Draw the graph of \(x^{2} - Dy^{2} = N\) over the reals. Mark the point \((\sqrt{N},0)\), which is on this graph. Now mark the point \((t\sqrt{N},u\sqrt{N})\), which is also on the graph. Continue marking points so that if (x, y) is the most recent point marked, then the next point marked is \((xt + Dyu,xu + yt)\). All of the points marked so far, apart from the first, have x > 0 and y > 0. Now, for each point (x, y) that has been marked, mark all of the points (±x, ±y) not yet marked.

The marked points divide the graph into intervals. Make the interval \(((\sqrt{N},0),(t\sqrt{N},u\sqrt{N})]\) a half-open interval, and then make the other intervals on this branch half-open by assigning endpoints to one interval. Make the intervals on the other half-open by mapping (x, y) in the right branch to \((-x,-y)\) on the left branch. If there are integer solutions to \(x^{2} - Dy^{2} = N\), then

  1. 1)

    No two solutions within the same (half-open) interval are equivalent,

  2. 2)

    Every interval has exactly one solution in each class, and

  3. 3)

    The order of solutions by class is the same in every interval.

Instead of starting with the point \((\sqrt{N},0)\), we could have started with any point (r, s) on the graph, and marked off the points corresponding to \(\pm (r + s\sqrt{D})(t + u\sqrt{D})^{n}\). The above three comments still apply.

The situation is similar in the case N < 0, except that the graph has the y-axis as its axis, and the x-axis is an axis of symmetry. If the negative Pell’s equation \(x^{2} - Dy^{2} = -1\) is solvable, then any of its solutions can be used to generate a correspondence between solutions to \(x^{2} - Dy^{2} = N\) and \(x^{2} - Dy^{2} = -N\).

Within a class there is a unique solution with x and y nonnegative, but smaller than any nonnegative solution. This is the minimal nonnegative solution for the class. There is also either one or two solutions so that y is nonnegative, and is less than or equal to any other nonnegative y in any solution (x, y) within the class. If there is one such solution, it is called the fundamental solution. If there are two such solutions, then they will be equivalent and their x-values will be negatives of each other. In this case, the solution with the positive x-value is called the fundamental solution for the class.

When tabulating solutions, it is usually convenient to make a list consisting of one solution from each class. Often, this list will consist of the minimal nonnegative solutions, or the fundamental solutions. Given any solution in a class, it is easy to find the fundamental solution or the minimal nonnegative solution for that class.

The results are summarized in the following

Theorem 4.4.2.

Given any solution in a class, all solutions in that class are derived from solutions to the equation \(x^{2} - Dy^{2} = 1\) . If (r,s) is any particular solution to \(x^{2} - Dy^{2} = N\) , (x,y) is any other solution to the same equation in the same class as (r,s) and if (t 1 ,u 1 ) is the fundamental solution to the Pell’s resolvent, then for some choice of signs + and −, and for some integer n

$$\displaystyle{ x + y\sqrt{D} = \pm (r + s\sqrt{D})(t_{1} + u_{1}\sqrt{D})^{n}. }$$
(4.4.8)

We can write formulas similar to those presented for cases N = ±1 and N = ±4 in Section 4.4.2.

4.4.4 Solving the Equation x 2Dy 2 = N for \(N < \sqrt{D}\)

When 1 < N 2 < D, apply the PQa algorithm with P 0 = 0, Q 0 = 1. Continue the computations until you reach the first i > 0 with \(G_{i}^{2} - DB_{i}^{2} = 1\) (i.e., \(Q_{i+1} = 1\) and i + 1 is even). For 1 ≤ j ≤ i, if \(G_{j}^{2} - DB_{j}^{2} = N/f^{2}\) for some f > 0, add fG j , fB j to the list of solutions. When done, the list of solutions will have the minimal positive member of each class.

The list of all solutions can be generated using the methods of the previous section. Alternatively, all positive solutions can be generated by extending the PQa algorithm indefinitely.

4.4.5 Solving the Equation x 2Dy 2 = N by Brute-Force Search

Let (t, u) be the minimal positive solution to \(x^{2} - Dy^{2} = N\). If N > 0, set y 1 = 0, and \(y_{2} = \sqrt{\frac{(t - 1)N} {2D}}\). If N < 0, set \(y_{1} = \sqrt{\frac{\vert N\vert } {2}}\), and \(y_{2} = \sqrt{\frac{(t + 1)\vert N\vert } {2D}}\). For y 1 ≤ y ≤ y 2, if N + Dy 2 is a square, set \(x = \sqrt{N + Dy^{2}}\). If (x, y) is not equivalent to (−x, y), add both to the list of solutions, otherwise just add (x, y) to the list. When finished, this list gives the fundamental solutions.

This method works well if y 2 is not too large, which means that \(\sqrt{\frac{(t \pm 1)\vert N\vert } {2D}}\) is not too large. Hence it suffices to search between the bounds y 1 and y 2.

To generate all solutions be performing this algorithm, refer to the structure of solutions of general Pell’s equation given in Section 4.4.3.

4.4.6 Numerical Examples

In order to see how the algorithms that we have presented work, we will examine a few numerical examples. Computations were done by using MATHEMATICA.

Example 1.

Consider the equations

$$\displaystyle{x^{2} - 109y^{2} = \pm 1.}$$

Apply the PQa algorithm with P 0 = 0 and Q 0 = 1. The following table gives the index, i, and then the several calculated quantities for \(i = -2\) to 30.

$$\displaystyle{\begin{array}{rrrrrrr} i&P_{i}&Q_{i}& a_{i}& G_{i}& B_{i}&G^{2} - 109B^{2} \\ - 2 & & & & 0 & 1 & - 109 \\ - 1 & & & & 1 & 0 & 1 \\ 0 & 0 & 1 & 10 & 10 & 1 & - 9 \\ 1 & 10 & 9 & 2 & 21 & 2 & 5\\ 2 & 8 & 5 & 3 & 73 & 7 & - 12 \\ 3 & 7 & 12 & 1 & 94 & 9 & 7\\ 4 & 5 & 7 & 2 & 261 & 25 & - 4 \\ 5 & 9 & 4 & 4 & 1138 & 109 & 15\\ 6 & 7 & 15 & 1 & 1399 & 134 & - 3 \\ 7 & 8 & 3 & 6 & 9532 & 913 & 3\\ 8 & 10 & 3 & 6 & 58591 & 5612 & - 15 \\ 9 & 8 & 15 & 1 & 68123 & 6525 & 4\\ 10 & 7 & 4 & 4 & 331083 & 31712 & - 7 \\ 11 & 9 & 7 & 2 & 730289 & 69949 & 12\\ 12 & 5 & 12 & 1 & 1061372 & 101661 & - 5 \\ 13 & 7 & 5 & 3 & 3914405 & 374932 & 9\\ 14 & 8 & 9 & 2 & 8890182 & 851525 & - 1 \\ 15 & 10 & 1 & 20 & 181718045 & 17405432 & 9\\ 16 & 10 & 9 & 2 & 372326272 & 35662389 & - 5 \\ 17 & 8 & 5 & 3 & 1298696861 & 124392599 & 12\\ 18 & 7 & 12 & 1 & 1671023133 & 160054988 & - 7 \\ 19 & 5 & 7 & 2 & 4640743127 & 444502575 & 4\\ 20 & 9 & 4 & 4 & 20233995641 & 1938065288 & - 15 \\ 21 & 7 & 15 & 1 & 24874738768 & 2382567863 & 3\\ 22 & 8 & 3 & 6 & 169482428249 & 16233472466 & - 3 \\ 23 & 10 & 3 & 6 & 1041769308262 & 99783402659 & 15\\ 24 & 8 & 15 & 1 & 1211251736511 & 116016875125 & - 4 \\ 25 & 7 & 4 & 4 & 5886776254306 & 563850903159 & 7\\ 26 & 9 & 7 & 2 & 12984804245123 & 1243718681443 & - 12 \\ 27 & 5 & 12 & 1 & 18871580499429 & 18075659584602 & 5\\ 28 & 7 & 5 & 3 & 69599545743410 & 6666427435249 & - 9 \\ 29 & 8 & 9 & 2 & 158070671986249 & 15140424455100 & 1\\ 30 & 10 & 1 & 20 & 3231012985468390 & 309474916537249 & - 9 \end{array} }$$

We have a 0 = 10, and the first i so that a i  = 2a 0 is i = 15, at which point a 15 = 20. Hence the period of a i is 15, which is odd, and so the equation \(x^{2} - 109y^{2} = -1\) has solutions. The minimal positive solution to \(x^{2} - 109y^{2} = -1\) is x = 8890182, y = 851525. The minimal positive solution to \(x^{2} - 109y^{2} = 1\) is x = 158070671986249, y = 15140424455100.

Example 2.

Let us examine now the equations

$$\displaystyle{x^{2} - 109y^{2} = \pm 4.}$$

As \(D \equiv 1\pmod 4\), apply the PQa algorithm with P 0 = 1 and Q 0 = 2. The following table gives the index, i, and the standard quantities for \(i = -2\) to 14.

$$\displaystyle{\begin{array}{rrrrrrr} i&P_{i}&Q_{i}&a_{i}& G_{i}& B_{i}&G^{2} - 109B^{2} \\ - 2 & & & & - 1 & 1 & - 108 \\ - 1 & & & & 2 & 0 & 4 \\ 0 & 1 & 2 & 5 & 9 & 1 & - 28 \\ 1 & 9 & 14 & 1 & 11 & 1 & 12\\ 2 & 5 & 6 & 2 & 31 & 3 & - 20 \\ 3 & 7 & 10 & 1 & 42 & 4 & 20\\ 4 & 3 & 10 & 1 & 73 & 7 & - 12 \\ 5 & 7 & 6 & 2 & 188 & 18 & 28\\ 6 & 5 & 14 & 1 & 261 & 25 & - 4 \\ 7 & 9 & 2 & 9 & 2537 & 243 & 28\\ 8 & 9 & 14 & 1 & 2798 & 268 & - 12 \\ 9 & 5 & 6 & 2 & 8133 & 779 & 20\\ 10 & 7 & 10 & 1 & 10931 & 1047 & - 20 \\ 11 & 3 & 10 & 1 & 19064 & 1826 & 12\\ 12 & 7 & 6 & 2 & 49059 & 4699 & - 28 \\ 13 & 5 & 14 & 1 & 68123 & 6535 & 4\\ 14 & 9 & 2 & 9 & 662166 & 63424 & - 28 \end{array} }$$

We have a 0 = 5, and the first i so that \(a_{i} = 2a_{0} - 1\) is i = 7, at which point a 7 = 9. Hence the period of a i is 7, which is odd, and so the equation \(x^{2} - 109y^{2} = -4\) has solutions. The minimal positive solution to \(x^{2} - 109y^{2} = -4\) is x = 261, y = 25. The minimal positive solution to \(x^{2} - 109y^{2} = 4\) is x = 68123, y = 6525.

Note that the third solution to \(x^{2} - 109y^{2} = \pm 4\) can be computed from

$$\displaystyle{\frac{1} {4}(261 + 25\sqrt{109})^{3} = 17780364 + 1703050\sqrt{109}.}$$

Upon dividing by 2, we get the minimal positive solution x = 8890182, y = 851525 to negative Pell’s equation \(x^{2} - 109y^{2} = -1\).

Example 3.

Consider the equation

$$\displaystyle{x^{2} - 129y^{2} = -5.}$$

From Theorem 4.1.4 it follows that if this equation is solvable, then it has exactly two classes of solutions.

Here \(N <\sqrt{D}\). Apply the PQa algorithm with P 0 = 0, Q 0 = 1.

$$\displaystyle{\begin{array}{rrrrrrr} i&P_{i}&Q_{i}& a_{i}& G_{i}& B_{i}&G^{2} - 129B^{2} \\ - 2 & & & & 0 & 1 & - 129 \\ - 1 & & & & 1 & 0 & 1 \\ 0 & 0 & 1 & 11 & 11 & 1 & - 8 \\ 1 & 11 & 8 & 2 & 23 & 2 & 13\\ 2&5&13&1&34&3&- 5 \\ 3 & 8 & 5 & 3 & 125 & 11 & 16\\ 4&7&16&1&159&14&- 3 \\ 5 & 9 & 3 & 6 & 1079 & 95 & 16\\ 6&9&16&1&1238&109&- 5 \\ 7 & 7 & 5 & 3 & 4793 & 422 & 13\\ 8&8&13&1&6031&531&- 8 \\ 9 & 5 & 8 & 2 & 16855 & 1484 & 1\\ 10&11&1&22&376841&33179&- 8 \end{array} }$$

The only f > 0 so that f 2 divides − 5 is f = 1. Reviewing the above for \(G_{j}^{2} - 129B_{j}^{2} = -5\), we find solutions (x, y) equal to (34,3) and (1238,109). Thus, there are two classes of solutions, and these are the minimal positive solutions for these classes.

Example 4.

Let us use the brute-force search method to find the fundamental solutions of

$$\displaystyle{x^{2} - 61y^{2} = 15.}$$

The minimal positive solution to Pell’s resolvent \(x^{2} - 61y^{2} = 1\) is x = 1766319049, y = 226153980. As N = 15 is positive, the lower search limit for y is 0, and the upper limit is

$$\displaystyle{\sqrt{\frac{15(1766319049 - 1)} {2 \cdot 61}} \approx 14736,702.}$$

So we search on y from 0 to 14736. Only y = 11 and y = 917 yield solutions, so the four fundamental solutions are x = ±86, y = 11, and x = ±7162, y = 917.

Example 5.

For the same equation above, we will apply now the LMM algorithm given in Section 4.3.

The only f > 0 so that f 2 divides 15 is f = 1. Set m = 15. The z’s with \(-15/2 <z \leq 15/2\) and \(z^{2} \equiv 61\pmod 15\) are z = ±1, z = ±4.

Upon performing the PQa algorithm with P 0 = 1, Q 0 = 15, and d = 61, the first Q i  = ±1 occurs at Q 9 = 1. The corresponding solution has \(x = G_{8} = 2593\) and \(y = B_{8} = 332\). For this (x, y), \(x^{2} - 61y^{2} = -15\). The equation \(x^{2} - 61y^{2} = -1\) is solvable and the minimal positive solution is x = 29718, y = 3805. Applying this to the solution (2593, 332) gives the solution x = 154117634, y = 19732741 to the equation \(x^{2} - 61y^{2} = 15\). This is equivalent to the fundamental solution (−86, 11).

Performing the PQa algorithm with \(P_{0} = -1\), Q 0 = 15, and d = 61, gives the first Q i  = ±1 at Q 4 = 1, yielding the fundamental solution (86, 11) to the equation \(x^{2} - 61y^{2} = 15\).

Performing the PQa algorithm with P 0 = 4, Q 0 = 15, and d = 61, gives the first Q i  = ±1 ate Q 10 = 1, yielding the fundamental solution (7162, 917) to the equation \(x^{2} - 61y^{2} = 15\).

Performing the PQa algorithm with \(P_{0} = -4\), Q 0 = 15, and d = 61, gives the first Q i  = ±1 at Q 3 = 1, yielding the solution (31, 4) to the equation \(x^{2} - 61y^{2} = -15\). Applying the minimal positive solution to \(x^{2} - 61y^{2} = -1\) gives the solution x = 1849678, y = 236827 to the equation \(x^{2} - 61y^{2} = 15\). This is equivalent to the fundamental solution (−7162, 917).

4.5 Solvability and Unsolvability of the Equation ax 2by 2 = c

Using the results in our papers [13, 14] and [17] we will present two general methods for solving the equation

$$\displaystyle{ ax^{2} - by^{2} = c. }$$
(4.5.1)

We will also give sufficient conditions such that equation (4.5.1) is unsolvable in positive integers. In the special case c = 1, the equation (4.5.1) was studied in Section 3.5.

The equation (4.5.1) is also considered in the recent paper [114], where a, b, c are positive integers with gcd(a, b) = 1. The author showed that if (4.5.1) is solvable, then it has infinitely many positive integer solutions. But his result is in fact a variant of the multiplication principle.

The following result given in [172] completely solves the problem of determining all solutions to equation (4.5.1).

Theorem 4.5.1.

Let a,b be positive integers such that gcd (a,b) = 1 and a is squarefree, and let c be a nonzero integer. Denote D = ab, N = ac. Then (u,v) is a solution to the general Pell’s equation

$$\displaystyle{ u^{2} - Dv^{2} = N }$$
(4.5.2)

if and only if \(\left (\frac{u} {a},v\right )\) is solution to (4.5.1) .

Proof.

Let (x, y) be a solution to (4.5.1). It follows that \((ax)^{2} - aby^{2} = ac\), so (ax, y) is a solution to the associated general Pell’s equation (4.5.2).

Conversely, if (u, v) is a solution to (4.5.2), from the relation \(u^{2} - abv^{2} = ac\) we obtain a | u 2. Taking into account that a is squarefree it follows that a | u. Therefore u = a 1 a and \((a_{1}a)^{2} - abv^{2} = ac\) yield \(aa_{1}^{2} - bv^{2} = c\), i.e., \(\left (\frac{u} {a},v\right )\) is a solution to (4.5.1). □ 

Remarks.

  1. 1)

    From the above result it is clear that (4.5.1) is solvable if and only if the associated general Pell’s equation (4.5.2) is solvable.

  2. 2)

    The assumption that a is squarefree is not a restriction. Indeed, if a = a 1 m 2 and a 1 is squarefree, then the equation (4.5.1) becomes \(a_{1}X^{2} - by^{2} = c\), where X = mx, i.e., an equation of the same type.

  3. 3)

    In order to solve (4.5.1) we determine all solutions (u, v) to the general Pell’s equation (4.5.2). The desired solutions are given by \(\left (\frac{u} {a},v\right )\).

The equation (4.5.1) is strongly connected to the general Pell’s equation (4.5.2) and to the Diophantine equation

$$\displaystyle{ as^{2} - bt^{2} = 1. }$$
(4.5.3)

The solvability of these three equations is studied in the following theorem [17]:

Theorem 4.5.2.

Suppose that gcd (a,b) = 1 and ab is not a perfect square. Then:

  1. 1)

    If the equations (4.5.2) and (4.5.3) are solvable, then (4.5.1) is also solvable and all of its solutions (x,y) are given by

    $$\displaystyle{ x = s_{0}u + bt_{0}v,\quad y = t_{0}u + as_{0}v }$$
    (4.5.4)

    where (u,v) is any solution to (4.5.2) and (s 0 ,t 0 ) is the minimal solution to (4.5.3) .

  2. 2)

    If the equations (4.5.1) and (4.5.3) are solvable, then (4.5.2) is also solvable.

  3. 3)

    If the equations (4.5.1) and (4.5.2) are solvable and there exist solutions (x,y), (u,v) such that

    $$\displaystyle{\frac{ux - bvy} {c} \quad \text{and}\quad \frac{-avx + uy} {c} }$$

    are both integers, then (4.5.3) is solvable.

Proof.

  1. 1)

    We have

    $$\displaystyle\begin{array}{rcl} & ax^{2} - by^{2} = a(s_{0}u + bt_{0}v)^{2} - b(t_{0}u + as_{0}v)^{2} =& {}\\ & = (as_{0}^{2} - bt_{0}^{2})(u^{2} - abv^{2}) = 1 \cdot c = c, & {}\\ \end{array}$$

    and it follows that (x, y), given in (4.5.4), is a solution to the equation (4.5.1).

    Conversely, let (x, y) be a solution to (4.5.1), and let (s 0, t 0) be the minimal solution to the equation (4.5.3). Then (u, v), where \(u = as_{0}x - bt_{0}y\) and \(v = -t_{0}x + s_{0}y\) is a solution to the general Pell’s equation (4.5.2). Solving the above system of linear equations with unknowns x and y yields \(x = s_{0}u + bt_{0}v\) and \(y = t_{0}u + as_{0}v\), i.e., (x, y) has the form (4.5.4).

  2. 2)

    If (x, y) and (s, t) are solutions to (4.5.1) and (4.5.3), respectively, then (u, v), with \(u = asx - bty\) and \(v = -tx + sy\) is a solution to (4.5.2). Moreover, each solution to (4.5.2) is of the above form. Indeed, if (u, v) is an arbitrary solution to (4.5.2), then (x, y), where \(x = su + btv\) and \(y = tu + asv\), is a solution to (4.5.1). Thus, solving the above system of linear equations in u, v, it follows that \(u = asx - bty\) and \(v = -tx + sy\).

  3. 3)

    Let (x, y) and (u, v) be solutions to (4.5.1) and (4.5.2), respectively, for which

    $$\displaystyle{s = \frac{ux - bvy} {c} \in \mathbb{Z}\quad \text{and}\quad t = \frac{-avx + uy} {c} \in \mathbb{Z}.}$$

    Then (s, t) is a solution to (4.5.3). □ 

Remarks.

  1. 1)

    The equation \(8x^{2} - y^{2} = 7\) is solvable and all of its solutions were determined in Section 4.1. For this equation, the associated equations (4.5.2) and (4.5.3) are \(u^{2} - 8v^{2} = 7\) and \(8s^{2} - t^{2} = 1\), respectively. It is interesting to see that both these equations are unsolvable.

  2. 2)

    In case of solvability of equations (4.5.2) and (4.5.3), the formulas (4.5.4) point out an alternative way to express the solutions to equation (4.5.1).

Theorem 4.5.3.

Let a,c be relatively prime positive integers, not both perfect squares, and let b and d be integers. The equation

$$\displaystyle{ ax^{2} - cy^{2} = ad - bc }$$
(4.5.5)

is solvable if and only if the numbers an + b and cn + d are perfect squares for some positive integer n. In this case, the number of such n’s is infinite.

Proof.

If (x 0, y 0) is a solution to the equation (4.5.5), then by Theorem 4.5.2, (x m , y m ) m ≥ 0, where

$$\displaystyle{ x_{m} = x_{0}u_{m} + cy_{0}v_{m},\quad y_{m} = ax_{0}v_{m} + y_{0}u_{m} }$$
(4.5.6)

are solutions to this equation. Here (u m , v m ) m ≥ 0 denotes the general solution to Pell’s equation \(u^{2} - acv^{2} = 1\).

Then \(ax_{m}^{2} - cy_{m}^{2} = ad - bc\), \(m = 0,1,2,\ldots\), hence

$$\displaystyle{ a(x_{m}^{2} - d) = c(y_{ m}^{2} - b),\quad m = 0,1,2,\ldots }$$
(4.5.7)

Since a and c are relatively prime, from (4.5.7) it follows that a | y m 2b and c | x m 2d, \(m = 0,1,2,\ldots\). Let

$$\displaystyle{ n_{m} = \frac{y_{m}^{2} - b} {a} = \frac{x_{m}^{2} - d} {c},\quad m = 0,1,2,\ldots }$$
(4.5.8)

Clearly, n m is a positive integer for each m and

$$\displaystyle{an_{m} + b = y_{m}^{2},\quad cn_{ m} + d = x_{m}^{2},\quad m = 0,1,2,\ldots }$$

i.e., the numbers an + b and cn + d are simultaneously perfect squares for infinitely many positive integers n.

If the equation (4.5.5) is not solvable in positive integers, then an + b and cn + d cannot be both perfect squares. Indeed, if we assume that there is a positive integer n 0 such that \(an_{0} + b = y_{0}^{2}\) and \(cn_{0} + d = x_{0}^{2}\) for some positive integers x 0, y 0, then by eliminating n 0 it follows that \(ax_{0}^{2} - by_{0}^{2} = ad - bc\), in contradiction with the unsolvability of equation (4.5.5). □ 

Theorem 4.5.4.

Let a and b be positive integers such that for all positive integers n, an + b is not a perfect square. Then the equations

$$\displaystyle{ ax^{2} - (am + v_{ 0})y^{2} = c,\quad m = 0,1,2,\ldots }$$
(4.5.9)

and

$$\displaystyle{ (am + w_{0})x^{2} - ay^{2} = c,\quad m = 0,1,2,\ldots }$$
(4.5.10)

are not solvable in positive integers. Here c is a nonzero integer and (u 0 ,v 0 ) and (w 0 ,s 0 ) are the minimal solutions to the equations \(au - bv = c\) and \(bw - as = c\) , respectively.

Proof.

The general solutions to the linear Diophantine equations \(au - bv = c\) and \(bw - as = c\) are (u m , v m ) m ≥ 0 and (w m , s m ) m ≥ 0, respectively, where

$$\displaystyle{u_{m} = u_{0} + bm,\quad v_{m} = v_{0} + am\quad \text{and}\quad w_{m} = w_{0} + am,\quad s_{m} = s_{0} + bm}$$

(see [198]). Assume now that equation (4.5.9) is solvable and let (x, y) be a solution. Then \(ax^{2} - (am + v_{0})y^{2} = c\). But by considerations above, \(c = au_{m} - bv_{m}\). It follows that

$$\displaystyle{ax^{2} - (am + v_{ 0})y^{2} = au_{ m} - bv_{m},}$$

hence the equation (4.5.3), where d = u m and c = u m is solvable. From Theorem 4.5.3 we obtain that an + b is a perfect square for some n, in contradiction with the hypothesis. □ 

Example 1.

The numbers 10n + 3 are not perfect squares, \(n = 0,1,2,\ldots\). Choosing c = 1, we find the minimal solutions to the equations \(10u - 3v = 1\) and \(3w - 10s = 1\). They are (1, 3) and (7, 2), respectively. From Theorem 4.5.4 it follows that the equations

$$\displaystyle{10x^{2} - (10m + 3)y^{2} = 1\quad \text{and}\quad (10m + 7)x^{2} - 10y^{2} = 1,\quad m = 0,1,2,\ldots }$$

are not solvable.

Remark.

In many situations it is not easy to find the minimal solutions (u 0, v 0) and (w 0, s 0) to the equations \(au - bv = c\) and \(bw - as = c\), respectively. In this cases we may replace (u 0, v 0) and (w 0, s 0) by any solution to the above equations and the results in Theorem 4.5.4 remain true.

Example 2.

The numbers 5n + 2 are not perfect squares for any positive integer n. The equations \(5u - 2v = c\) and \(2w - 5s = c\) have (c, 2c) and (3c, c) among their solutions, respectively. It follows that \(u_{m} = c + 2m\), \(v_{m} = 2c + 5m\), and \(w_{m} = 3c + 5m\), \(s_{m} = c + 2m\), \(m = 0,1,2,\ldots\).

From Theorem 4.5.3 we obtain that the equations

$$\displaystyle{5x^{2} - (5m + 2c)y^{2} = c\quad \text{and}\quad (5m + 3c)x^{2} - 5y^{2} = c,\quad m = 0,1,2,\ldots }$$

are not solvable.

Example 3.

In a similar manner, starting with the nonsquare numbers 3n + 2, \(n = 0,1,2,\ldots\), we deduce that equations

$$\displaystyle{3x^{2} - (3m + c)y^{2} = c\quad \text{and}\quad (3m + 2c)x^{2} - 3y^{2} = c,\quad m = 0,1,2,\ldots }$$

are not solvable in positive integers.

There are many situations in which the unsolvability of an equation of the type (4.5.1) can be proven by using modular arithmetics arguments.

Example 4 ([193]).

The equation

$$\displaystyle{(4m + 3)x^{2} - (4n + 1)y^{2} = 1}$$

where m and n are positive integers, is not solvable.

Indeed, x 2, y 2 ≡ 0 or \(1\pmod 4\) and so (4m + 3)x 2 ≡ 0 or \(3\pmod 4\) and (4n + 1)y 2 ≡ 0 or \(1\pmod 4\). By combining the residues, we obtain

$$\displaystyle{(4m + 3)x^{2} - (4n + 1)y^{2}\not\equiv 1\pmod 4.}$$

Example 5 ([192]).

In a similar manner, we can prove that equations

$$\displaystyle{(4k + 2)x^{2} - (4l + 3)y^{2} = 1\quad \text{and}\quad 7mx^{2} - (7n + 1)y^{2} = 1,}$$

where k, l and m, n are positive integers, are also not solvable.

A criterion for solvability (unsolvability) for a class of general Pell’s equations is given in [100] (see also subsection 4.2.4).

Theorem 4.5.5.

For N a squarefree integer, the equation

$$\displaystyle{ x^{2} - 2y^{2} = N }$$
(4.5.11)

is solvable if and only if it is solvable modulo N.

Proof.

By multiplicativity, it suffices to show that \(x^{2} - 2y^{2} = N\) has a solution for \(N = -1\), N = 2, and N = p for p an odd prime such that 2 is congruent to a square modulo p. For \(N = -1\), use \(1^{2} - 2 \cdot 1^{2} = -1\); for N = 2, use \(2^{2} - 2 \cdot 1^{2} = 2\).

Now suppose p is an odd prime such that 2 is congruent to a square modulo p. Find x, y such that x 2 − 2y 2 is divisible by p but not by p 2 (if it is divisible by p 2, fix that by replacing x with x + p). Now form the ideal \((x + y\sqrt{D},p)\). Its norm divides p 2 and x 2 − 2y 2, so it must be p. □ 

Incidentally, one can replace 2 by any integer D such that \(\mathbb{Q}(\sqrt{D})\) has unique factorization, provided that \(x^{2} - Dy^{2} = -1\) has a solution. It turns out (but is by no means obvious!) that unique factorization implies that D is prime, and it is believed (but not proved) that \(\mathbb{Q}(\sqrt{D})\) has unique factorization for about 75 % of the primes D. Moreover, existence of a solution of \(x^{2} - Dy^{2} = -1\) then implies \(D \equiv 1\pmod 4\), but nor every prime congruent to 1 modulo 4 will work (try D = 5).

4.6 Solving the General Pell Equation by Using Quadratic Rings

The main purpose of this section is to present an algorithm for finding all positive integer solutions to the general Pell’s equation

$$\displaystyle{ x^{2} - Dy^{2} = k }$$
(4.6.1)

where d is a nonsquare positive integer and k is a nonzero integer. We will follow the method described in [76] (see also [171]).

Let (x, y) be an integral solution of (4.6.1), i.e., \(x^{2} - Dy^{2} = k\). We are going to use the results in Section 2.2.2 We have N(μ) = k, where \(\mu = x + \sqrt{D}y \in R\). If \(\varepsilon _{0}\) is the fundamental unit of the ring R found in Theorem 3.4.1, then we will denote

$$\displaystyle{\varepsilon = \left \{\begin{array}{lll} \varepsilon _{0}, &\text{if}&N(\varepsilon _{0}) = 1 \\ \varepsilon _{0}^{2},&\text{if}&N(\varepsilon _{0}) = -1. \end{array} \right.}$$

Then the vectors (1, 1) and \(l(\varepsilon )\) form a base in the linear space \(\mathbb{R}^{2}\). Indeed, if \(\alpha (1,1) +\beta l(\varepsilon ) = 0\), with \(\alpha,\beta \in \mathbb{R}\), then \(\alpha +\beta \ln \vert \varepsilon \vert = 0\) and \(\alpha +\beta \ln \vert \overline{\varepsilon }\vert = 0\). Since \(\ln \vert \overline{\varepsilon }\vert = -\ln \vert \varepsilon \vert \neq 0\), from the previous two relations it follows that \(\alpha =\beta = 0\).

If \(\mu = x + y\sqrt{D} \in R\) and N(μ) = k, then k ≠ 0 implies μ ≠ 0, i.e., the vector l(μ) is well defined in \(\mathbb{R}^{2}\). By using the fact that (1, 1) and \(l(\varepsilon )\) form a base in \(\mathbb{R}^{2}\), we deduce the existence of \(\alpha,\gamma \in \mathbb{R}\) such that \(l(\mu ) =\alpha (1,1) +\gamma l(\varepsilon )\). This means that

$$\displaystyle{\ln \mu =\alpha +\gamma \ln \vert \varepsilon \vert \quad \text{and}\quad \ln \overline{\mu } =\alpha +\gamma \ln \vert \overline{\varepsilon }\vert.}$$

In particular, it follows that

$$\displaystyle{\ln \vert k\vert =\ln \vert N(\mu )\vert =\ln \vert \mu \vert +\ln \vert \overline{\mu }\vert = 2\alpha +\gamma \ln \vert N(\varepsilon )\vert = 2\alpha,}$$

i.e.,

$$\displaystyle{\alpha = \frac{\ln \vert k\vert } {2} \quad \text{and}\quad l(\mu ) = \frac{\ln \vert k\vert } {2} (1,1) +\gamma l(\varepsilon ).}$$

Let a be the closest integer to γ, and let \(\mu _{0} =\varepsilon ^{-\alpha }\mu\). Then μ ∼ μ 0 and \(N(\mu _{0}) = N(\mu ) = k\). In addition,

$$\displaystyle{l(\mu _{0}) = \frac{\ln \vert k\vert } {2} (1,1) +\gamma _{1}l(\varepsilon ),}$$

where \(\vert \gamma _{1}\vert \leq \frac{1} {2}\) and \(\gamma _{1} =\gamma -a\). Therefore

$$\displaystyle{\ln \vert \mu _{0}\vert = \frac{\ln \vert k\vert } {2} +\gamma _{1}\ln \varepsilon \quad \text{and}\quad \ln \vert \overline{\mu }_{0}\vert = \frac{\ln \vert k\vert } {2} +\gamma _{1}\ln \vert \overline{\varepsilon }\vert = \frac{\ln \vert k\vert } {2} -\gamma _{1}\ln \varepsilon }$$

(we have used here that \(\varepsilon> 1\)). It follows that

$$\displaystyle{\left \vert \ln \vert \mu _{0}\vert -\frac{\ln \vert k\vert } {2} \right \vert \leq \frac{1} {2}\ln \varepsilon \quad \text{and}\quad \left \vert \ln \vert \overline{\mu }_{0}\vert -\frac{\ln \vert k\vert } {2} \right \vert \leq \frac{1} {2}\ln \varepsilon.}$$

The above inequalities can be written as

$$\displaystyle{\ln \sqrt{\frac{\vert k\vert } {\varepsilon }} \leq \ln \vert \mu _{0}\vert \leq \ln \sqrt{\varepsilon \vert k\vert }\quad \text{and}\quad \ln \sqrt{\frac{\vert k\vert } {\varepsilon }} \leq \ln \vert \overline{\mu }_{0}\vert \leq \ln \sqrt{\varepsilon \vert k\vert }.}$$

We obtain

$$\displaystyle{ \sqrt{\frac{\vert k\vert } {\varepsilon }} \leq \vert \mu _{0}\vert \leq \sqrt{\varepsilon \vert k\vert }\quad \text{and}\quad \sqrt{\frac{\vert k\vert } {\varepsilon }} \leq \vert \overline{\mu }_{0}\vert \leq \sqrt{\varepsilon \vert k\vert }. }$$
(4.6.2)

The numbers | μ 0 | and \(\vert \overline{\mu }_{0}\vert\) can be written as \(s + t\sqrt{D}\), where s and t are positive integers. Since \(t\sqrt{D} \leq \max \{\vert \mu _{0}\vert,\vert \overline{\mu }_{0}\vert \}\leq \sqrt{\varepsilon \vert k\vert }\), we have

$$\displaystyle{ t \leq \sqrt{\frac{\varepsilon \vert k\vert } {D}} \quad \text{and}\quad s \leq \sqrt{\varepsilon \vert k\vert }. }$$
(4.6.3)

We will now describe the actual algorithm.

Step 1. Search for elements \(\mu _{1},\mu _{2},\ldots,\mu _{r}\) in R of the form \(s + t\sqrt{D}\) such that s, t are positive integers satisfying inequalities (4.6.3) and N(μ i ) = k, \(i = 1,2,\ldots,r\).

From the inequalities (4.6.3) it follows that there are finitely many such μ’s in R. This fact also follows from Theorem 2.2.3.

Step 2. From Theorem 3.4.1 it follows that all elements μ ∈ R with N(μ) = k are of the form \(\mu = \pm \mu _{i}\varepsilon ^{l}\) or \(\mu = \pm \overline{\mu }_{i}\varepsilon ^{l}\), for some \(i \in \{ 1,2,\ldots,r\}\) and some integer l.

Finally, let us mention that we can determine the fundamental unit \(\varepsilon _{0} \in R\) in a finite number of steps. For this part we refer to Section 3.3, where we employed continued fractions.

4.7 Another Algorithm for Solving General Pell’s Equation

In what follows we will present a different algorithm for solving the general Pell’s equation (4.6.1). Our approach is based on the one given in [171] and [95].

It suffices to consider solutions (x, y) to (4.6.1) such that the positive integers x and y are relatively prime.

If \(\vert k\vert <\sqrt{D}\), then we apply Theorem 3.3.1. When \(k\neq (-1)^{n-1}q_{n+1}\) for all n, the equation (4.6.1) is not solvable. When \(k = (-1)^{n-1}q_{n+1}\) for some n, the pair (h n , k n ) is a solution to the general Pell’s equation (4.6.1) and all other of its integral solutions are given by

$$\displaystyle{x + y\sqrt{D} = (\pm h_{n} \pm k_{n}\sqrt{D})\varepsilon ^{l},\quad l \in \mathbb{Z},}$$

where is the fundamental solution of the Pell’s resolvent.

If \(\vert k\vert> \sqrt{D}\), then we write k = δ k 0, where δ = ±1 and k 0 is a positive integer. Since x and y are relatively prime, there exist integers x 1 and y 1 such that \(xy_{1} - yx_{1} =\delta\).

It follows that

$$\displaystyle\begin{array}{rcl} & (xx_{1} - Dyy_{1})^{2} - D = (xx_{1} - Dyy_{1})^{2} - D(xy_{1} - yx_{1})^{2} = & {}\\ & = (x^{2} - Dy^{2})(x_{1}^{2} - Dy_{1}^{2}) = k(x_{1}^{2} - Dy_{1}^{2}) =\delta k_{0}(x_{1}^{2} - Dy_{1}^{2}).& {}\\ \end{array}$$

Hence

$$\displaystyle{ (xx_{1} - Dyy_{1})^{2} - D =\delta k_{ 0}(x_{1}^{2} - Dy_{ 1}^{2}). }$$
(4.7.1)

If (x 0, y 0) is a solution to the equation \(xy_{1} - yx_{1} =\delta\), then the general solution to this equation is given by

$$\displaystyle{x_{1} = x_{0} + tx\quad \text{and}\quad y_{1} = y_{0} + ty,\quad t \in \mathbb{Z}.}$$

We have

$$\displaystyle{xx_{1} - Dyy_{1} = xx_{0} - Dyy_{0} + t(x^{2} - Dy^{2}) = xx_{ 0} - Dyy_{0} + t\delta k_{0}.}$$

We will choose t such that

$$\displaystyle{ \vert xx_{1} - Dyy_{1}\vert \leq \frac{k_{0}} {2}. }$$
(4.7.2)

Denoting by l the positive integer | xx 1Dyy 1 | , from (4.7.1) we obtain

$$\displaystyle{ x_{1}^{2} - Dy_{ 1}^{2} = \frac{l^{2} - D} {\delta k_{0}} =\eta h, }$$
(4.7.3)

where η = ±1 and h is a positive integer.

Using the inequalities \(\sqrt{D} <k_{0}\) and \(l <\frac{k_{0}} {2}\), from (4.7.3) it follows that

$$\displaystyle{h \leq \frac{\max \{D,l^{2}\}} {k_{0}} <\frac{\max \left \{k_{0}^{2}, \frac{k_{0}^{2}} {4} \right \}} {k_{0}} = \frac{k_{0}^{2}} {k_{0}} = k_{0}.}$$

If h < k 0, then we apply again Theorem 3.3.1 and obtain x 1 and y 1 such that \(x_{1}^{2} - Dy_{1}^{2} =\eta h\). From the equalities \(xy_{1} - yx_{1} =\delta\) and \(xx_{1} - Dyy_{1} = \pm l\) we deduce the following formulas:

$$\displaystyle{ x = \frac{-\delta Dy_{1} \pm lx_{1}} {\eta h} \quad \text{and}\quad y = \frac{-\delta x_{1} \pm ly_{1}} {\eta h}. }$$
(4.7.4)

Hence the integers x and y can be obtained from the equality

$$\displaystyle{\eta h(x + y\sqrt{D}) = (x_{1} + y_{1}\sqrt{D})(\pm l -\delta \sqrt{D}).}$$

Taking norms in the above equality yields

$$\displaystyle{h^{2}(x^{2} - Dy^{2}) = (x_{ 1}^{2} - Dy_{ 1}^{2})(l^{2} - D) =\eta h \cdot \eta h \cdot \delta k_{ 0} = h^{2}\delta k_{ 0},}$$

and so \(x^{2} - Dy^{2} =\delta k_{0} = k\).

Therefore, if x and y given in (4.7.4) are integers, then (x, y) is a solution to the general Pell’s equation (4.6.1).

If \(h> \sqrt{D}\), then we apply again the described procedure.

The considerations above can be summarized in the following algorithm. Step 1. Find all solutions to the congruence

$$\displaystyle{l^{2} \equiv D\pmod k_{ 0},}$$

where l is a positive integer and \(0 \leq l \leq \frac{k_{0}} {2}\). Denote by \(l_{1},l_{2},\ldots,l_{r}\) those satisfying the inequalities \(0 \leq l \leq \frac{k_{0}} {2}\). Set

$$\displaystyle{\frac{l_{i}^{2} - D} {\delta k_{0}} =\eta _{i}h_{i},\quad i = 1,2,\ldots,r,}$$

where η i  = ±1 and h i is a positive integer.

Step 2. If \(k_{0} <\sqrt{D}\), apply Theorem 3.3.1.

Step 3. If \(k_{0}> \sqrt{D}\), consider the equations

$$\displaystyle{x_{1}^{2} - Dy_{ 1}^{2} =\eta _{ i}h_{i},\quad i = 1,2,\ldots,r.}$$

From the previous observations we have 0 < h i  < k 0, \(i =,1,2\ldots,r\).

Step 4. Fix \(i \in \{ 1,2,\ldots,r\}\).

  1. I.

    If \(h_{i} <\sqrt{D}\), apply Theorem 3.3.1 to get the solutions to the equation \(x_{i}^{2} - Dy_{i}^{2} =\eta _{i}h_{i}\). Then the solutions (x, y) are among those given by

    $$\displaystyle{ x = \frac{-\delta Dy_{i} \pm l_{i}x_{i}} {\eta _{i}h_{i}} \quad \text{and}\quad y = \frac{-\delta x_{i} \pm l_{i}y_{i}} {\eta _{i}h_{i}}. }$$
    (4.7.5)
  2. II.

    If \(h_{i}> \sqrt{D}\), repeat Step 3, replacing δ by η i and k 0 by h i . Since 0 < h i  < k 0, after finitely many operations we will find all solutions to the given equation.

Remark.

The two algorithms presented in Sections 4.5 and 4.6 are comparable. None is superior to the other and, moreover, they complete one another. The algorithm in Section 4.5 is preferable for large k’s or large D’s. The second is more efficient for small k’s, for example when k satisfies the inequalities \(-\sqrt{D} <k <\sqrt{D}\) (see also Subsection 4.3.4).

4.8 The Diophantine Equation ax 2 + bxy + cy 2 = N

The standard approach to solving the equation

$$\displaystyle{ ax^{2} + bxy + cy^{2} = N }$$
(4.8.1)

in relatively prime integers x, y, is via reduction of quadratic forms, as in [127]. There is a parallel approach in [71] which uses continued fractions.

However, in a memoir of 1770, Lagrange, gave a more direct method for solving (4.8.1) when \(\gcd (a,b,c) =\gcd (a,N) = 1\) and \(D = b^{2} - 4ac> 0\) is not a perfect square. This seems to have been largely overlooked. (Admittedly, the necessity part of his proof is long and not easy to follow.)

In [175], equation (4.8.1) is solved when N = ±μ, where

$$\displaystyle{\mu =\min _{(x,y)\neq (0,0)}\vert ax^{2} + bxy + cy^{2}\vert.}$$

The approach is similar to Lagrange’s reduction to the case N = ±1.

In the doctoral dissertation [157] the equation (4.8.1) is also discussed, using a standard convergent sufficiency condition of Lagrange, which resulted in the restriction D ≥ 16, thus making rigorous the necessity part of Lagrange’s discussion. Only the case b = 0 is discussed in detail, along the lines of [57].

The approach using the convergent criterion of Lemma 4.3.1, which results in no restriction on D, while allowing us to deal with the non-convergent case, without having to appeal to the case μ = 1 in [175], whose proof is somewhat complicated.

The continued fractions approach also had the advantage that it produces the solution (x, y) with least positive y from each class, if \(\gcd (a,N) = 1\).

The assumption \(\gcd (a,N) = 1\) involves no loss of generality. For as pointed out by Gauss in his Disquisitiones (see [95]), there exist relatively prime integers α, γ such that \(a\alpha ^{2} + b\alpha \gamma + c\gamma ^{2} = A\), where gcd(A, N) = 1. Then, if \(\alpha \delta -\beta \gamma = 1\), the unimodular transformation \(x =\alpha X +\beta Y\), \(y =\gamma X +\delta Y\) converts \(ax^{2} + bxy + cy^{2}\) to \(AX^{2} + BXY + CY ^{2}\). Also, the two forms represent the same integers.

Let us illustrate how we can solve (4.8.1) via the reduction of the quadratic form in the left-hand side. By multiplying both sides of (4.8.1) by 4a and completing the square we obtain

$$\displaystyle{ (2ax + by)^{2} - Dy^{2} = 4aN, }$$
(4.8.2)

where \(D = b^{2} - 4ac\). Assume that D > 0 and D is not a perfect square. Then (4.8.2) is a general Pell’s equation. Let (u n , v n ) be the general solution to its Pell’s resolvent \(u^{2} - Dv^{2} = 1\) and let (α, β) be the fundamental solution of the class K to the equation \(X^{2} - DY ^{2} = 4aN\) (see Section 4.1). Following [39], we have:

Theorem 4.8.1.

All integer solutions (x n ,y n ) n≥1 to (4.8.1) are given by

$$\displaystyle{ \left \{\begin{array}{ll} x_{n} = \frac{(\alpha -b\beta )u_{n} - (b\alpha - D\beta )v_{n}} {2a}\\ y_{ n} =\beta u_{n} +\alpha v_{n}, \end{array} \right. }$$
(4.8.3)

where (u n ,v n ) n≥1 is the solution to the Pell’s resolvent, and (α,β) is the fundamental solution of the class K.

Proof.

Let \(X = 2ax + by\), Y = y, and N 1 = 4aN. By Theorem 4.1.3, we obtain the general solution to \(X^{2} - DY ^{2} = N_{1}\)

$$\displaystyle{X_{n} =\alpha u_{n} + D\beta v_{n}\quad \text{and}\quad Y _{n} =\beta u_{n} +\alpha v_{n}.}$$

Solving the linear system

$$\displaystyle{\left \{\begin{array}{rl} 2ax_{n} + by_{n}& =\alpha u_{n} + D\beta v_{n} \\ y_{n}& =\beta u_{n} +\alpha v_{n} \end{array} \right.}$$

we get the formulas (4.8.3).

Now let us show that x n is an integer. To prove this, it is enough to show 2aαb β and 2aα bβ D. Indeed, we have \(\alpha -b\beta = 2ax\) and

$$\displaystyle{\alpha b -\beta D =\alpha b -\beta (b^{2} - 4ac) = (\alpha -b\beta )b + 4ac\beta = 2axb + 4ac\beta = 2a(x\beta + 2c\beta ),}$$

and the properties follow. □ 

Example.

The equation in Example 5, page 54, in the book [22] is reduced to

$$\displaystyle{ x^{2} - 5xy + y^{2} = -3. }$$
(4.8.4)

In the reference [22] the equation (4.8.4) is solved by Fermat’s method of infinite descent. Let us illustrate the method in Theorem 4.8.1 for finding the solutions to (4.8.4). The equation (4.8.4) is equivalent to

$$\displaystyle{(2x - 5y)^{2} - 21y^{2} = -12.}$$

Let \(X = 2x - 5y\) and Y = y. We obtain the general Pell’s equation \(X^{2} - 21Y ^{2} = -12\). The Pell’s resolvent \(u^{2} - 21v^{2} = 1\) has the fundamental solution (u 1, v 1) = (55, 12), hence its general solution (u n , v n ) n ≥ 1 is given by \(u_{n} + v_{n}\sqrt{21} = (55 + 12\sqrt{21})^{n}\). Using the upper bounds in the Remark after Theorem 4.1.3, we have

$$\displaystyle\begin{array}{rcl} & 0 \leq \vert X\vert \leq \sqrt{\frac{\vert N\vert u_{1 } + N} {2}} = \sqrt{\frac{12 \cdot 55 - 12} {2}} = \sqrt{6 \cdot 54} = 18,& {}\\ & 0 <Y \leq \sqrt{\frac{\vert N\vert u_{1 } - N} {2D}} = \sqrt{\frac{12 \cdot 55 + 12} {2 \cdot 21}} = \sqrt{16} = 4. & {}\\ \end{array}$$

Therefore, we obtain the possibilities | X | = 0, 1, , 18 and Y = 1, 2, 3, 4. Then we get four solutions (3, 1), (−3, 1), (18, 4), (−18, 4) to the equation \(X^{2} - 21Y ^{2} = -12\). It is easy to check that these solutions are not associated with each other and they generates four classes of solutions to the above general Pell’s equation. From Theorem 4.8.1 we get all integer solutions to equation (4.8.4):

$$\displaystyle{\begin{array}{ll} (4u_{n} + 18v_{n},u_{n} + 3v_{n}), &(u_{n} + 3v_{n},u_{n} - 3v_{n}), \\ (19u_{n} + 87v_{n},4u_{n} + 18v_{n}),&(u_{n} - 3v_{n},4u_{n} - 18v_{n}),\ n \geq 1.\end{array} }$$

These four classes of solutions give a partition of the solution obtained in the above-mentioned reference [22].

4.9 Thue’s Theorem and the Equations x 2Dy 2 = ±N

In this section, following the papers [86, 87, 128] and [225] we show how to obtain explicit representations of certain integers in the form x 2Dy 2 for small D > 1, using a constructive version of Thue’s theorem based on Euclid’s algorithm. Amongst other things, if \(u^{2} \equiv D\pmod N\), \(D\not\equiv 1\pmod N\) is solvable and \(\gcd (D,N) = 1\), N odd, we show how to find the following representations:

$$\displaystyle{\begin{array}{|c|c|} \hline N = 8k \pm 1 & N = x^{2} - 2y^{2} \\ & - N = x^{2} - 2y^{2} \\ \hline N = 12k + 1 & N = x^{2} - 3y^{2} \\ \hline N = 12k - 1 & - N = x^{2} - 3y^{2} \\ \hline N = 5k + 1 & N = x^{2} - 5y^{2} \\ \hline N = 5k - 1 & - N = x^{2} - 5y^{2} \\ \hline N = 24k + 1\text{ or }24k - 5 & N = x^{2} - 6y^{2} \\ \hline N = 24k - 1\text{ or }24k + 5 & - N = x^{2} - 6y^{2} \\ \hline N = 28k + 1,\ 28k + 9\text{ or }28k + 25& N = x^{2} - 7y^{2} \\ \hline N = 28k - 1,\ 28k - 9\text{ or }28k - 25& - N = x^{2} - 7y^{2} \\ \hline \end{array} }$$

4.9.1 Euclid’s Algorithm and Thue’s Theorem

Let a and b be natural numbers, a > b, where b does not divide a. Let r 0 = a, r 1 = b, and for 1 ≤ k ≤ n, \(r_{k-1} = r_{k}q_{k} + r_{k+1}\), where 0 < r k+1 < r k and r n  = 0. Define sequences \(s_{0},s_{1},\ldots,s_{n+1}\) and \(t_{0},t_{1},\ldots,t_{n+1}\) by

$$\displaystyle{s_{0} = 1,\ s_{1} = 0,\ t_{0} = 0,\ t_{1} = 1,\ t_{k+1} = -q_{k}t_{k} + t_{k-1},\ s_{k+1} = -q_{k}s_{k} + s_{k-1},}$$

for 1 ≤ k ≤ n. Then the following are easily proved by induction:

  1. (i)

    \(s_{k} = (-1)^{k}\vert s_{k}\vert,\ t_{k} = (-1)^{k+1}\vert t_{k}\vert\);

  2. (ii)

    \(0 = \vert s_{1}\vert <\vert s_{2}\vert <\ldots \vert s_{n+1}\vert\);

  3. (iii)

    \(1 = \vert t_{1}\vert <\vert t_{2}\vert <\ldots <\vert t_{n+1}\vert\);

  4. (iv)

    \(a = \vert t_{k}\vert r_{k-1} + \vert t_{k-1}\vert r_{k}\) for 1 ≤ k ≤ n + 1;

  5. (v)

    \(r_{k} = s_{k}a + t_{k}b\) for 1 ≤ k ≤ n + 1.

Theorem 4.9.1 (Thue).

Let a and b be integers, a > b > 1 with \(\gcd (a,b) = 1\) . Then the congruence \(bx \equiv y\pmod a\) has a solution in nonzero integers x and y satisfying \(\vert x\vert <\sqrt{a}\) , |y|≤ a.

Proof.

As \(r_{n} =\gcd (a,b) = 1\), \(a> \sqrt{a}> 1\), and the remainders \(r_{0},\ldots,r_{n}\) in Euclid’s algorithm decrease strictly to 1, there is a unique index k such that \(r_{k-1}> \sqrt{a} \geq r_{k}\). Then the equation \(a = \vert t_{k}\vert r_{k-1} + \vert t_{k-1}\vert r_{k}\) gives \(a \geq \vert t_{k}\vert r_{k-1}> \vert t_{k}\vert \sqrt{a}\). Hence \(\vert t_{k}\vert <\sqrt{a}\).

Finally, \(r_{k} = s_{k}a + t_{k}b\), so \(bt_{k} \equiv r_{k}\pmod a\) and we can take x = t k , y = r k . □ 

4.9.2 The Equation x 2Dy 2 = N with Small D

Let N ≥ 1 be an odd integer, D > 1 and not a perfect square. Then a necessary condition for solvability of the equation \(x^{2} - Dy^{2} = \pm N\) with gcd(x, y) = 1 is that the congruence \(u^{2} \equiv D\pmod N\) is solvable. From now on we assume this, together with gcd(D, N) = 1 and 1 < u < N. Then the Jacobi symbol \(\left (\frac{D} {N}\right ) = 1\). We note that if N is prime, then \(\left (\frac{D} {N}\right ) = 1\) also implies that \(u^{2} \equiv D\pmod N\) is solvable.

If we take a = N and b = u in Euclid’s algorithm, the integers r k 2Dt k 2 decrease strictly for \(k = 0,\ldots,n\), from a 2 to 1 − Dt n 2 and are always multiples of N. For

$$\displaystyle{r_{k}^{2} - Dt_{ k}^{2} \equiv t_{ k}^{2}u^{2} - Dt_{ k}^{2} \equiv t_{ k}^{2}(u^{2} - D) \equiv 0\pmod N.}$$

If k is chosen so that \(r_{k-1}> \sqrt{N}> r_{k}\), as in the proof of Thue’s theorem, then as

$$\displaystyle{ N = r_{k-1}\vert t_{k}\vert + r_{k}\vert t_{k-1}\vert> r_{k-1}\vert t_{k}\vert, }$$
(4.9.1)

we have \(\vert t_{k}\vert <\sqrt{N}\) and

$$\displaystyle{ -DN <r_{k}^{2} - Dt_{ k}^{2} <N. }$$
(4.9.2)

Hence \(r_{k}^{2} - Dt_{k}^{2} = -lN\), − 1 < l < D. In fact, 1 ≤ l < D, so

$$\displaystyle{ -DN <r_{k}^{2} - Dt_{ k}^{2} \leq -N. }$$
(4.9.3)

Also \(r_{k}^{2} + lN = Dt_{k}^{2}\) and hence Dt k 2 > lN,

$$\displaystyle{ \vert t_{k}\vert> \sqrt{\frac{lN} {D}}. }$$
(4.9.4)

From equation (4.9.1), N > r k−1 | t k  | and inequality (4.9.4) implies

$$\displaystyle{ r_{k-1} <\sqrt{\frac{DN} {l}}. }$$
(4.9.5)

4.9.3 The Equations x 2 − 2y 2 = ±N

The assumption \(\left ( \frac{2} {N}\right ) = 1\) is equivalent to \(N \equiv \pm 1\pmod 8\). Also 1 ≤ l < 2, so l = 1 and (4.9.3) gives \(r_{k}^{2} - 2t_{k}^{2} = -N\). Hence from equation (4.9.5) with D = 2, \(r_{k-1} <\sqrt{2N}\) and

$$\displaystyle{-N = r_{k}^{2} - 2t_{ k}^{2} <r_{ k-1}^{2} - 2t_{ k-1}^{2} <r_{ k-1}^{2} <2N.}$$

Thus \(r_{k-1}^{2} - 2t_{k-1}^{2} = N\).

Example.

Let N = 10000000033, a prime of the form 8n + 1. Then u = 87196273 gives k = 10, r 10 = 29015, \(t_{10} = -73627\), r 9 = 118239, t 9 = 44612 and \(r_{10}^{2} - 2t_{10}^{2} = -N\), \(r_{9}^{2} - 2t_{9}^{2} = N\).

Remark.

We can express r k−1 and t k−1 in terms of r k and t k . The method is useful later for delineating cases when D = 5, 6, 7:

Using the identities

$$\displaystyle{ (r_{k}r_{k-1} -Dt_{k}t_{k-1})^{2} -D(t_{ k}r_{k-1} -t_{k-1}r_{k})^{2} = (r_{ k}^{2} -Dt_{ k}^{2})(r_{ k-1}^{2} -Dt_{ k-1}^{2}) }$$
(4.9.6)

and

$$\displaystyle{ (-1)^{k}N = r_{ k}t_{k-1} - r_{k-1}t_{k}, }$$
(4.9.7)

we deduce that

$$\displaystyle{ r_{k}r_{k-1} - Dt_{k}t_{k-1} =\varepsilon N, }$$
(4.9.8)

where \(\varepsilon = \pm 1\).

From equation (4.9.8) we see that \(\varepsilon = 1\), as t k t k−1 < 0. Hence

$$\displaystyle{ r_{k}r_{k-1} + DT_{k}T_{k-1} = N, }$$
(4.9.9)

where T k  = | t k  | . Then solving equations (4.9.7) and (4.9.9) with D = 2 for r k−1 and T k−1 yields

$$\displaystyle{r_{k-1} = -r_{k} + 2T_{k},\quad T_{k-1} = T_{k} - r_{k}.}$$

The integers N, | N | ≤ 200, such that the equation \(x^{2} - 2y^{2} = N\) is solvable are: ± 1, ± 2, ± 4, ± 7, ± 8, ± 9, ± 14, ± 16, ± 17, ± 18, ± 23, ± 25, ± 28, ± 31, ± 32, ± 34, ± 36, ± 41, ± 46, ± 47, ± 49, ± 50, ± 56, ± 62, ± 63, ± 64, ± 68, ± 71, ± 72, ± 73, ± 79, ± 81, ± 82, ± 89, ± 92, ± 94, ± 97, ± 98, ± 100, ± 103, ± 112, ± 113, ± 119, ± 121, ± 124, ± 126, ± 127, ± 128, ± 136, ± 137, ± 142, ± 144, ± 146, ± 151, ± 153, ± 158, ± 161, ± 162, ± 164, ± 167, ± 169, ± 175, ± 178, ± 184, ± 188, ± 191, ± 193, ± 194, ± 196, ± 199, ± 200.

The following table presents the numbers k(2, N) of classes of solutions and the sets \(\mathcal{K}(2,N)\) of fundamental solutions of classes of \(x^{2} - 2y^{2} = N\), when the equations are solvable and N is positive or negative, | N | ≤ 18 [161].

$$\displaystyle{\begin{array}{|l|c|l|} \hline x^{2} - 2y^{2} = N &k(2,N)&\mathcal{K}(2,N) \\ \hline \hline x^{2} - 2y^{2} = 2& 1 &(2,1) \\ \hline x^{2} - 2y^{2} = -2 & 1 &(4,3) \\ \hline x^{2} - 2y^{2} = 4 & 1 &(6,4) \\ \hline x^{2} - 2y^{2} = -4 & 1 &(2,2) \\ \hline x^{2} - 2y^{2} = 7 & 2 &(3,1),\ (5,3) \\ \hline x^{2} - 2y^{2} = -7 & 2 &(1,2),\ (5,4) \\ \hline x^{2} - 2y^{2} = 8 & 1 &(4,2) \\ \hline x^{2} - 2y^{2} = -8 & 1 &(8,6) \\ \hline x^{2} - 2y^{2} = 9 & 1 &(9,6) \\ \hline x^{2} - 2y^{2} = -9 & 1 &(3,3) \\ \hline x^{2} - 2y^{2} = 14 & 2 &(4,1),\ (8,5) \\ \hline x^{2} - 2y^{2} = -14 & 2 &(2,3),\ (6,5) \\ \hline x^{2} - 2y^{2} = 16 & 1 &(12,8) \\ \hline x^{2} - 2y^{2} = -16 & 1 &(4,4) \\ \hline x^{2} - 2y^{2} = 17 & 2 &(5,2),\ (7,4) \\ \hline x^{2} - 2y^{2} = -17 & 2 &(1,3),\ (9,7) \\ \hline x^{2} - 2y^{2} = 18 & 1 &(6,3) \\ \hline x^{2} - 2y^{2} = -18 & 1 &(12,9) \\ \hline \end{array} }$$

Here are four examples of general Pell’s equations \(x^{2} - 2y^{2} = N\), with N big: k(2, 833) = 6 and \(\mathcal{K}(2,833) =\) {(29,2), (31,8), (35,14), (49,28), (61,38), (79,52)}; k(2, 1666) = 5 and \(\mathcal{K}(2,1666) =\) {(42,7), (46,15), (54,25), (62,33), (98,63)}; k(2, 2737) = 7 and \(\mathcal{K}(2,2737) =\) {(53,6), (55,12), (57,16), (75,38), (107,66), (117,74), (135,88)}; k(2, 3689) = 8 and \(\mathcal{K}(2,3689) =\) {(61,4), (67,20), (71,26), (83,40), (89,46), (109,64), (121,74), (167,110)}.

4.9.4 The Equations x 2 − 3y 2 = ±N

The assumption \(\left ( \frac{3} {N}\right ) = 1\) is equivalent to \(N \equiv \pm 1\pmod 12\). From equation (4.9.3), we have \(-3N <r_{k}^{2} - 3t_{k}^{2} \leq -N\). Hence \(r_{k}^{2} - 3t_{k}^{2} = -2N\) or − N.

Case 1. Assume \(N \equiv 1\pmod 12\). Then \(r_{k}^{2} - 3t_{k}^{2} = -N\) would imply the contradiction \(r_{k}^{2} \equiv -1\pmod 3\).

Hence \(r_{k}^{2} - 3t_{k}^{2} = -2N\) and inequality (4.9.5) implies \(r_{k-1} <\sqrt{\frac{3N} {2}}\). Hence

$$\displaystyle{-2N = r_{k}^{2} - 3t_{ k}^{2} <r_{ k-1}^{2} - 3t_{ k-1}^{2} <r_{ k-1}^{2} <\frac{3N} {2}.}$$

Consequently, \(r_{k-1}^{2} - 3t_{k-1}^{2} = N\).

We find \(2r_{k-1} = -r_{k} + 3T_{k}\) and \(2T_{k-1} = -r_{k} + T_{k}\).

Case 2. Assume \(N \equiv -1\pmod 12\). Then \(r_{k}^{2} - 3t_{k}^{2} = -2N\) would imply the contradiction \(r_{k}^{2} \equiv 0\pmod 3\). Hence \(r_{k}^{2} - 3t_{k}^{2} = -N\) and inequality (4.9.5) implies \(r_{k-1} <\sqrt{3N}\). Hence

$$\displaystyle{-N = r_{k}^{2} - 3t_{ k}^{2} <r_{ k-1}^{2} - 3t_{ k-1}^{2} <r_{ k-1}^{2} <3N.}$$

Consequently, \(r_{k-1}^{2} - 3t_{k-1}^{2} = N\) or 2N. However, \(r_{k-1}^{2} - 3t_{k-1}^{2} = N\) implies the contradiction \(r_{k-1}^{2} \equiv -1\pmod 3\). Hence \(r_{k-1}^{2} - 3t_{k-1}^{2} = 2N\).

We find \(r_{k-1} = -r_{k} + 3T_{k}\) and \(T_{k-1} = -r_{k} + T_{k}\).

The integers N, | N | ≤ 200, such that the equation \(x^{2} - 3y^{2} = N\) is solvable are: 1, 4, 6, 9, 13, 16, 22, 24, 25, 33, 36, 37, 46, 49, 52, 54, 61, 64, 69, 73, 78, 81, 88, 94, 96, 97, 100, 109, 117, 118, 121, 132, 141, 142, 144, 148, 150, 157, 166, 169, 177, 181, 184, 193, 196, 198, − 2, − 3, − 8, − 11, − 12, − 18, − 23, − 26, − 27, − 32, − 39, − 44, − 47, − 48, − 50, − 59, − 66, − 71, − 72, − 74, − 75, − 83, − 92, − 98, − 99, − 104, − 107, − 108, − 111, − 122, − 128, − 131, − 138, − 143, − 146, − 147, − 156, − 162, − 167, − 176, − 179, − 183, − 188, − 191, − 192, − 194, − 200.

The following table contains the numbers k(3, N) of classes of solutions and the sets \(\mathcal{K}(3,N)\) of fundamental solutions of classes of \(x^{2} - 3y^{2} = N\), when the equations are solvable and N is positive or negative, | N | ≤ 27 [161].

$$\displaystyle{\begin{array}{|l|c|l|} \hline x^{2} - 3y^{2} = N &k(3,N)&\mathcal{K}(3,N) \\ \hline \hline x^{2} - 3y^{2} = 4& 1 &(4,2) \\ \hline x^{2} - 3y^{2} = 6 & 1 &(3,1) \\ \hline x^{2} - 3y^{2} = 9 & 1 &(6,3) \\ \hline x^{2} - 3y^{2} = 13 & 2 &(4,1),\ (5,2) \\ \hline x^{2} - 3y^{2} = 16 & 1 &(8,4) \\ \hline x^{2} - 3y^{2} = 22 & 2 &(5,1),\ (7,3) \\ \hline x^{2} - 3y^{2} = 24 & 1 &(6,2) \\ \hline x^{2} - 3y^{2} = 25 & 1 &(10,5) \\ \hline x^{2} - 3y^{2} = -3 & 1 &(3,2) \\ \hline x^{2} - 3y^{2} = -8 & 1 &(2,2) \\ \hline x^{2} - 3y^{2} = -11 & 2 &(1,2),\ (4,3) \\ \hline x^{2} - 3y^{2} = -12 & 1 &(6,4) \\ \hline x^{2} - 3y^{2} = -18 & 1 &(3,3) \\ \hline x^{2} - 3y^{2} = -23 & 2 &(2,3),\ (5,4) \\ \hline x^{2} - 3y^{2} = -26 & 2 &(1,3),\ (7,5) \\ \hline x^{2} - 3y^{2} = -27 & 1 &(9,6) \\ \hline \end{array} }$$

Here are five example of equations \(x^{2} - 3y^{2} = N\), with N big: k(3, 121) = 3 and \(\mathcal{K} =\) {(13,4), (14,5), (22,11)}; k(3, 253) = 4 and \(\mathcal{K}(3,253) =\) {(16,1), (19,6), (20,7), (29,14)}; k(3, 1573) = 5 and \(\mathcal{K}(3,1573) =\) {(40,3), (41,6), (44,11), (55,22), (64,29)}; k(3, 3289) = 8 and \(\mathcal{K}(3,3289) =\) {(58,5), (59,8), (61,12), (67,20), (74,27), (86,37), (94,43), (101,48)}’ k(3, 3718) = 6 and \(\mathcal{K}(3,3718) =\) {(61,1), (65,13), (71,21), (79,29), (91,39), (119,59)}.

4.9.5 The Equations x 2 − 5y 2 = ±N

The assumption \(\left ( \frac{5} {N}\right ) = 1\) is equivalent to \(N \equiv \pm 1\pmod 5\). Then from equation (4.9.3), we have \(-5N <r_{k}^{2} - 5t_{k}^{2} \leq -N\). Hence \(r_{k}^{2} - 5t_{k}^{2} = -4N,\ -3N,\ -2N\) or − N. We cannot have \(r_{k}^{2} - 5t_{k}^{2} = -3N\), as then \(\left (\frac{5} {3}\right ) = 1\). Neither can we have \(r_{k}^{2} - 5t_{k}^{2} = -2N\), as N is odd.Case 1. Assume \(N \equiv 1\pmod 5\). Then \(r_{k}^{2} - 5t_{k}^{2} = -N\) would imply the contradiction \(r_{k}^{2} \equiv -1\pmod 5\). Hence \(r_{k}^{2} - 5t_{k}^{2} = -4N\). Then r k and t k are both odd. Also, inequality (4.9.5) implies \(r_{k-1} <\sqrt{\frac{5N} {4}}\). Hence \(-N \leq r_{k-1}^{2} - 5t_{k-1}^{2} \leq N\).

Then as in the remark above, we can show that

  1. (i)

    if \(r_{k-1}^{2} - 5t_{k-1}^{2} = -N\), then

    $$\displaystyle{4r_{k-1} = -3r_{k} + 4T_{k},\quad 4T_{k-1} = -r_{k} + 3T_{k},}$$

    hence \(r_{k} \equiv -T_{k}\pmod 4\).

  2. (ii)

    if \(r_{k-1}^{2} - 5t_{k-1}^{2} = N\), then

    $$\displaystyle{4r_{k-1} = -r_{k} + 5T_{k},\quad 4T_{k-1} = -r_{k} + T_{k},}$$

    hence \(r_{k} \equiv T_{k}\pmod 4\).

Case 2. Assume \(N \equiv -1\pmod 5\). Then \(r_{k}^{2} - 5t_{k}^{2} = -4N\) would imply the contradiction \(r_{k}^{2} \equiv 4\pmod 5\). Hence \(r_{k}^{2} - 5t_{k}^{2} = -N\). Then not both r k and t k are odd. Also, inequality (4.9.5) implies \(r_{k-1} <\sqrt{5N}\) and we deduce that \(-N <r_{k-1}^{2} - 5t_{k-1}^{2} \leq 4N\). Consequently, \(r_{k-1}^{2} - 5t_{k-1}^{2} = N\) or 4N.

Then, as in the remark above, we can show

  1. (i)

    if \(r_{k-1}^{2} - 5t_{k-1}^{2} = N\), then

    $$\displaystyle{r_{k-1} = -2r_{k} + 5T_{k},\quad T_{k-1} = -r_{k} + 2T_{k},}$$

    hence \(r_{k-1} \equiv -2r_{k}\pmod 5\).

  2. (ii)

    If \(r_{k-1}^{2} - 5t_{k-1}^{2} = 4N\), then

    $$\displaystyle{r_{k-1} = -r_{k} + 5T_{k},\quad T_{k-1} = -r_{k} + T_{k},}$$

    hence \(r_{k-1} \equiv -r_{k}\pmod 5\).

Here is a complete classification of the possible cases:

  1. 1.

    \(N = 5k + 1\). Then \(r_{k}^{2} - 5t_{k}^{2} = -4N\), while r k and t k are odd.

    1. (i)

      \(r_{k} \equiv -T_{k}\pmod 4\). Then \(r_{k-1}^{2} - 5t_{k-1}^{2} = -N\).

    2. (ii)

      \(r_{k} \equiv T_{k}\pmod 4\). Then \(r_{k-1}^{2} - 5t_{k-1}^{2} = N\).

  2. 2.

    \(N = 5k - 1\). Then \(r_{k}^{2} - 5t_{k}^{2} = -N\), while r k and t k are not both odd.

    1. (i)

      \(r_{k-1} \equiv -2r_{k}\pmod 5\). Then \(r_{k-1}^{2} - 5t_{k-1}^{2} = N\).

    2. (ii)

      \(r_{k-1} \equiv -r_{k}\pmod 5\). Then \(r_{k-1}^{2} - 5t_{k-1}^{2} = 4N\).

The integers N, | N | ≤ 200, such that the equation \(x^{2} - 5y^{2} = N\) is solvable are: ± 1, ± 4, ± 5, ± 9, ± 11, ± 16, ± 19, ± 20, ± 25, ± 29, ± 31, ± 36, ± 41, ± 44, ± 45, ± 49, ± 55, ± 59, ± 61, ± 64, ± 71, ± 76, ± 79, ± 80, ± 81, ± 89, ± 95, ± 99, ± 100, ± 101, ± 109, ± 116, ± 121, ± 124, ± 125, ± 131, ± 139, ± 144, ± 145, ± 149, ± 151, ± 155, ± 164, ± 169, ± 171, ± 176, ± 179, ± 180, ± 181, ± 191, ± 196, ± 199.

The following table gives the numbers k(5, N) and the sets \(\mathcal{K}(5,N)\) of the equations \(x^{2} - 5y^{2} = N\), when they are solvable and N is positive or negative, | N | ≤ 29 [161].

$$\displaystyle{\begin{array}{|l|c|l|} \hline x^{2} - 5y^{2} = N &k(5,N)&\mathcal{K}(5,N) \\ \hline \hline x^{2} - 5y^{2} = 4& 3 &(3,1),\ (7,3),\ (18,8) \\ \hline x^{2} - 5y^{2} = 5 & 1 &(5,2) \\ \hline x^{2} - 5y^{2} = 9 & 1 &(27,12) \\ \hline x^{2} - 5y^{2} = 11 & 2 &(4,1),\ (16,7) \\ \hline x^{2} - 5y^{2} = 16 & 3 &(6,2),\ (14,6),\ (36,16) \\ \hline x^{2} - 5y^{2} = 19 & 2 &(8,3),\ (12,5) \\ \hline x^{2} - 5y^{2} = 20 & 3 &(5,1),\ (10,4),\ (25,11) \\ \hline x^{2} - 5y^{2} = 25 & 1 &(45,20) \\ \hline x^{2} - 5y^{2} = -4 & 3 &(1,1),\ (4,2),\ (11,5) \\ \hline x^{2} - 5y^{2} = -5 & 1 &(20,9) \\ \hline x^{2} - 5y^{2} = -9 & 1 &(6,3) \\ \hline x^{2} - 5y^{2} = -11 & 2 &(3,2),\ (13,6) \\ \hline x^{2} - 5y^{2} = -16 & 3 &(2,2),\ (8,4),\ (22,10) \\ \hline x^{2} - 5y^{2} = -19 & 2 &(1,2),\ (31,14) \\ \hline x^{2} - 5y^{2} = -20 & 3 &(5,3),\ (15,7),\ (40,18) \\ \hline x^{2} - 5y^{2} = -25 & 1 &(10,5) \\ \hline x^{2} - 5y^{2} = -29 & 2 &(4,3),\ (24,11) \\ \hline \end{array} }$$

Here are three example of equations \(x^{2} - 5y^{2} = N\), with N big: k(5, 1276) = 11 and \(\mathcal{K}(5,1276) =\) {(36,2), (39,7), (41,9), (49,15), (59,21), (76,30), (84,34), (111,47), (141,61), (211,93), (284,126)}; k(5, 1936) = 8 and \(\mathcal{K}(5,1936) =\) {(46,6), (54,14), (84,32), (116,48), (154,66), (206,90), (294,130), (396,176)}; k(5, 9196) = 18 and \(\mathcal{K}(5,9196) =\) {(96,2), (99,11), (104,18), (111,25), (121,33), (139,45), (149,51), (176,66), (201,79), (229,93), (264,110), (321,137), (351,151), (429,187), (499,219), (576,254), (671,297), (824,366)}.

4.9.6 The Equations x 2 − 6y 2 = ±N

The assumption \(\left ( \frac{6} {N}\right ) = 1\) is equivalent to \(N \equiv \pm 1\pmod 24\) or \(N \equiv \pm 5\pmod 24\). Then from equation (4.9.3), we have \(-6N <r_{k}^{2} - 6t_{k}^{2} \leq -N\). Hence \(r_{k}^{2} - 6t_{k}^{2} = -5N,\ -4N,\ -3N,\ -2N\) or − N. Only − 4N is ruled out immediately and the other possibilities can occur.

As with the case D = 5, there is a complete classification of the possible cases:

  1. 1.

    \(N = 24k - 1\) or 24k + 5.

    1. (i)

      \(r_{k} \equiv 0\pmod 3\). Then \(r_{k}^{2} - 6t_{k}^{2} = -3N\), \(r_{k-1}^{2} - 6t_{k-1}^{2} = -N\).

    2. (ii)

      \(r_{k}\not\equiv 0\pmod 3\). Then \(r_{k}^{2} - 6t_{k}^{2} = -N\).

      1. (a)

        \(r_{k-1} \equiv 0\pmod 2\). Then \(r_{k-1}^{2} - 6t_{k-1}^{2} = 2N\).

      2. (b)

        \(r_{k-1} \equiv 1\pmod 2\). Then \(r_{k-1}^{2} - 6t_{k-1}^{2} = 5N\).

  2. 2.

    \(N = 24k + 1\) or \(24k - 5\):

    1. (i)

      \(r_{k} \equiv 0\pmod 2\). Then \(r_{k}^{2} - 6t_{k}^{2} = -2N\), \(r_{k-1}^{2} - 6t_{k-1}^{2} = N\).

    2. (ii)

      \(r_{k} \equiv 1\pmod 2\). Then \(r_{k}^{2} - 6t_{k}^{2} = -5N\).

      1. (a)

        \(r_{k} \equiv T_{k}\pmod 5\). Then \(r_{k-1}^{2} - 6t_{k-1}^{2} = N\).

      2. (b)

        \(r_{k} \equiv -T_{k}\pmod 5\). Then \(r_{k-1}^{2} - 6t_{k-1}^{2} = -2N\), \(r_{k-2}^{2} - 6t_{k-2}^{2} = N\).

The integers N, | N | ≤ 200, such that \(x^{2} - 6y^{2} = N\) is solvable are: 1, 3, 4, 9, 10, 12, 16, 19, 25, 27, 30, 36, 40, 43, 46, 48, 49, 57, 58, 64, 67, 73, 75, 76, 81, 90, 94, 97, 100, 106, 108, 115, 120, 121, 129, 138, 139, 142, 144, 145, 147, 160, 163, 169, 171, 172, 174, 184, 190, 192, 193, 196, − 2, − 5, − 6, − 8, − 15, − 18, − 20, − 23, − 24, − 29, − 32, − 38, − 45, − 47, − 50, − 53, − 54, − 60, − 69, − 71, − 72, − 80, − 86, − 87, − 92, − 95, − 96, − 98, − 101, − 114, − 116, − 125, − 128, − 134, − 135, − 141, − 146, − 149, − 150, − 152, − 159, − 162, − 167, − 173, − 180, − 188, − 191, − 194, − 197, − 200.

The following table gives the numbers k(6, N) and the sets \(\mathcal{K}(6,N)\) of equations \(x^{2} - 6y^{2} = N\), when they are solvable and N is positive or negative, | N | ≤ 25 [161].

$$\displaystyle{\begin{array}{|l|c|l|} \hline x^{2} - 6y^{2} = N &k(6,N)&\mathcal{K}(6,N) \\ \hline \hline x^{2} - 6y^{2} = 3& 1 &(3,1) \\ \hline x^{2} - 6y^{2} = 4 & 1 &(10,4) \\ \hline x^{2} - 6y^{2} = 9 & 1 &(15,6) \\ \hline x^{2} - 6y^{2} = 10 & 2 &(4,1),\ (8,3) \\ \hline x^{2} - 6y^{2} = 12 & 1 &(6,2) \\ \hline x^{2} - 6y^{2} = 16 & 1 &(20,8) \\ \hline x^{2} - 6y^{2} = 19 & 2 &(5,1),\ (13,5) \\ \hline x^{2} - 6y^{2} = 25 & 3 &(7,2),\ (11,4),\ (25,10) \\ \hline x^{2} - 6y^{2} = -2 & 1 &(2,1) \\ \hline x^{2} - 6y^{2} = -5 & 2 &(1,1),\ (7,3) \\ \hline x^{2} - 6y^{2} = -6 & 1 &(12,5) \\ \hline x^{2} - 6y^{2} = -8 & 1 &(4,2) \\ \hline x^{2} - 6y^{2} = -15 & 2 &(3,2),\ (9,4) \\ \hline x^{2} - 6y^{2} = -18 & 1 &(6,3) \\ \hline x^{2} - 6y^{2} = -20 & 2 &(2,2),\ (14,6) \\ \hline x^{2} - 6y^{2} = -23 & 2 &(1,2),\ (19,8) \\ \hline \end{array} }$$

Here are three examples of equations \(x^{2} - 6y^{2} = N\), with N big: k(6, 625) = 5 and \(\mathcal{K}(6,625) =\) {(29,6), (35,10), (55,20), (73,28), (125,50)}; k(6, 2185) = 8 and \(\mathcal{K}(6,2185) =\) {(47,2), (49,6), (61,16), (79,26), (83,28), (113,42), (173,68), (211,84)}; k(6, 9025) = 9 and \(\mathcal{K}(6,9025) =\) {(97,8), (101,14), (133,38), (155,50), (175,60), (209,76), (337,132), (389,154), (475,190)}.

4.9.7 The Equations x 2 − 7y 2 = ±N

The assumption \(\left ( \frac{7} {N}\right ) = 1\) is equivalent to \(N \equiv 1,3,9,19,25,27\pmod 28\).

As with the case D = 6, there is a complete classification of the possible cases:

  1. 1.

    \(N = 28k + 1,\ 28k + 9\), or 28k + 25.

    1. (i)

      \(r_{k} \equiv T_{k}\pmod 2\). Then \(r_{k}^{2} - 7t_{k}^{2} = -6N\).

      1. (a)

        \(r_{k} \equiv -T_{k}\pmod 6\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = -3N\).

        1. (1)

          \(r_{k-1} \equiv -T_{k-1}\pmod 3\). Then \(r_{k-2}^{2} - 7t_{k-2}^{2} = N\).

        2. (2)

          \(r_{k-1} \equiv T_{k-1}\pmod 3\). Then \(r_{k-2}^{2} - 7t_{k-2}^{2} = 2N\).

      2. (b)

        \(r_{k} \equiv T_{k}\pmod 6\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = N\).

    2. (ii)

      \(r_{k}\not\equiv T_{k}\pmod 2\). Then \(r_{k}^{2} - 7t_{k}^{2} = -3N\).

      1. (a)

        \(r_{k} \equiv -T_{k}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = N\).

      2. (b)

        \(r_{k} \equiv T_{k}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = 2N\).

  2. 2.

    \(N = 28k + 3,\ 28k + 19\), or 28k + 27.

    1. (i)

      \(r_{k} \equiv T_{k}\pmod 2\). Then \(r_{k}^{2} - 7t_{k}^{2} = -2N\).

      1. (a)

        \(r_{k-1} \equiv -T_{k-1}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = -N\).

      2. (b)

        \(r_{k-1} \equiv T_{k-1}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = 3N\).

    2. (ii)

      \(r_{k}\not\equiv T_{k}\pmod 2\). Then \(r_{k}^{2} - 7t_{k}^{2} = -N\).

      1. (a)

        \(r_{k-1} \equiv -T_{k-1}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = 3N\).

      2. (b)

        \(r_{k-1} \equiv T_{k-1}\pmod 3\). Then \(r_{k-1}^{2} - 7t_{k-1}^{2} = 6N\).

In cases 1(a)(2) and 2(i), the equations \(r_{k-2}^{2} - 7t_{k-2}^{2} = 2N\) and \(r_{k}^{2} - 7t_{k}^{2} = -2N\) give rise to equations \(x^{2} - 7y^{2} = N,\ -N\), respectively, if we write \(x + y\sqrt{7} = (r_{k-2} + t_{k-2}\sqrt{7})(3 + \sqrt{7})\) and \((r_{k} + t_{k}\sqrt{7})/(3 + \sqrt{7})\), respectively. For if \(x + y\sqrt{7} = (r + t\sqrt{7})/(3 + \sqrt{7})\), where r and t are odd, then \(x = \frac{3r - 7t} {2}\) and \(y = \frac{3t - r} {2}\) are integers and \(x^{2} - 7y^{2} = (r^{2} - 7t^{2})/2\).

We note that 1(a)(2) cannot occur unless \(N \equiv 0\pmod 3\). Then we have

$$\displaystyle\begin{array}{rcl} r_{k-1} + \frac{-r_{k} + 7T_{k}} {6},\quad T_{k-1} = \frac{-r_{k} + 5T_{k}} {6} & &{}\end{array}$$
(4.9.10)
$$\displaystyle\begin{array}{rcl} r_{k-2} = \frac{-r_{k-1} + 7T_{k-1}} {3},\quad T_{k-2} = \frac{-r_{k-1} + T_{k-1}} {3}.& &{}\end{array}$$
(4.9.11)

Then (4.9.6) implies \(r_{k-1} + T_{k-1} = -r_{k} + 2T_{k} \equiv -r_{k} - T_{k} \equiv 0\pmod 3\). Also (4.9.7) implies \(r_{k-1} \equiv T_{k-1}\pmod 3\). Hence 3 divides r k−1 and T k−1 and the equation \(r_{k-1}^{2} - 7T_{k-1}^{2} = -3N\) then implies that 3 divides N.

Example.

N = 57. The congruence \(u^{2} \equiv 7\pmod 57\) has solutions \(u \equiv \pm 8,\pm 11\pmod 57\). Then u = 0 gives k = 2, r 1 = 8, t 1 = 1, r 2 = 1, r 2 = 1, \(t_{2} = -7\), \(r_{k}^{2} - 7t_{k}^{2} = -6N\) and \(r_{k-1}^{2} - 7t_{k-1}^{2} = N\), while u = 11 gives k = 2, r 1 = 11, t 1 = 1, r 2 = 2, \(t_{2} = -5\) and \(r_{k}^{2} - 7t_{k}^{2} = -3N\) and \(r_{k-1}^{2} - 7t_{k-1}^{2} = 2N\).

The integers N, | N | ≤ 200, such that \(x^{2} - 7y^{2} = N\) is solvable are: 1, 2, 4, 8, 9, 16, 18, 21, 25, 29, 32, 36, 37, 42, 49, 50, 53, 57, 58, 64, 72, 74, 81, 84, 93, 98, 100, 106, 109, 113, 114, 116, 121, 128, 133, 137, 141, 144, 148, 149, 162, 168, 169, 177, 186, 189, 193, 196, 197, 200, − 3, − 6, − 7, − 12, − 14, − 19, − 24, − 27, − 28, − 31, − 38, − 47, − 48, − 54, − 56, − 59, − 62, − 63, − 75, − 76, − 83, − 87, − 94, − 96, − 103, − 108, − 111, − 112, − 118, − 124, − 126, − 131, − 139, − 147, − 150, − 152, − 159, − 166, − 167, − 171, − 174, − 175, − 188, − 192, − 199.

The following table contains the numbers k(7, N) and the sets \(\mathcal{K}(7,N)\) of the equations \(x^{2} - 7y^{2} = N\), when they are solvable and N is positive or negative, | N | ≤ 29 [161].

$$\displaystyle{\begin{array}{|l|c|l|} \hline x^{2} - 7y^{2} = N &k(7,N)&\mathcal{K}(7,N) \\ \hline \hline x^{2} - 7y^{2} = 2& 1 &(3,1) \\ \hline x^{2} - 7y^{2} = 4 & 1 &(16,6) \\ \hline x^{2} - 7y^{2} = 8 & 1 &(6,2) \\ \hline x^{2} - 7y^{2} = 9 & 3 &(4,1),\ (11,4),\ (24,9) \\ \hline x^{2} - 7y^{2} = 16 & 1 &(32,12) \\ \hline x^{2} - 7y^{2} = 18 & 3 &(5,1),\ (9,3),\ (19,7) \\ \hline x^{2} - 7y^{2} = 21 & 2 &(7,2),\ (14,5) \\ \hline x^{2} - 7y^{2} = 25 & 1 &(40,15) \\ \hline x^{2} - 7y^{2} = 29 & 2 &(6,1),\ (27,10) \\ \hline x^{2} - 7y^{2} = -3 & 2 &(2,1),\ (5,2) \\ \hline x^{2} - 7y^{2} = -6 & 2 &(1,1),\ (13,5) \\ \hline x^{2} - 7y^{2} = -7 & 1 &(21,8) \\ \hline x^{2} - 7y^{2} = -12 & 2 &(4,2),\ (10,4) \\ \hline x^{2} - 7y^{2} = -14 & 1 &(7,3) \\ \hline x^{2} - 7y^{2} = -19 & 2 &(3,2),\ (18,7) \\ \hline x^{2} - 7y^{2} = -24 & 2 &(2,2),\ (26,10) \\ \hline x^{2} - 7y^{2} = -27 & 4 &(1,2),\ (6,3),\ (15,6),\ (34,13) \\ \hline \end{array} }$$

Here are three examples of equations \(x^{2} - 7y^{2} = N\), with N big: k(7, 2349) = 10 and \(\mathcal{K}(7,2349) =\) {(51,6), (54,9), (61,14), (82,25), (93,30), (114,39), (131,46), (194,71), (243,90), (282,105)}; k(7, 3249) = 9 and \(\mathcal{K}(7,3249) =\) {(64,11), (71,16), (76,19), (111,36), (132,45), (209,76), (232,85), (281,104), (456,171)}; k(7, 4617) = 12 and \(\mathcal{K}(7,4617) =\) {(68,1), (72,9), (75,12), (93,24), (117,36), (128,41), (163,56), (180,63), (240,87), (348,129), (387,144), (523,196)}.