You are on page 1of 2

How to Find the Fundamental Solution to Pell’s Equation

In this paper we descibe a method for computing the fundamental solution (x, y) to Pell’s
equation, namely the equation
x2 − ny 2 = 1, (1)
where n is an arbitrary non-square positive integer and x and y are positive integers. By the
fundamental solution, we mean the unique solution with minimal value of x (and thus of y as
well). As it turns out, there are infinitely many solutions to equation (1), and each one can be
easily derived from the fundamental solution. Our solution involves the theory of continued
fractions, which we do not descibe here. For those interested in this method, please see [1]. It
is also worthwhile to consider the modified Pell equation, i.e., the equation
x2 − ny 2 = ±1, (2)
where n is as in equation (1) and once again x and y are positive integers.
Before describing our method in detail, it is worthwhile to discuss a bit of the theory of
quadratic orders. To do so, we first need a few definitions. For all of these definitions, we
assume that n is an arbitrary non-square positive integer.
Definition 1: The quadratic order Rn is the set of real numbers defined as follows:
√ √
Rn = Z[ n] = {x + y n : x, y ∈ Z}.

Definition 2: Let α = x + y n be an arbitrary element of Rn (i.e., x and y are arbitrary
integers). The conjugate of α, written as α is given by the following formula:

α = x − y n. (3)

Definition 3: Once again we let α = x + y n be an arbitrary element of Rn . The norm of
α, written as N (α) is given by the following formula:
N (α) = αα = x2 − ny 2 . (4)
It is easy to see from this definition that the norm is multiplicative, i.e., for all pairs of elements
α, β in Rn , we have
N (αβ) = N (α)N (β). (5)

Definition 4: A unit of Rn is an element of R of norm ±1.



Definition 5: The fundamental unit n of Rn is the unique unit x + y n of R with x and y
both positive.

1
2

Note that by this definition,


√ (x, y) is the fundamental solution to the modified Pell equation
(2) if and only if x + y n is the fundamentlal unit n of the quadratic order Rn . It should also
be noted that for some quadratic orders, the norm of the funamental unit is 1 and for others
it is −1. It should√also be noted that if N (n ) = −1, then by equation (5) we have N (2n ) = 1,
so if n = x1 + y1 n, where x1 and y1 are positive integers, then we have

2n = (x1 + y1 n)2 √
= x21 + ny 2
√ 1 + 2x1 y1 n
= x + y n,
where
x = x21 + ny12 ;
(6)
y = 2x1 y1 .
Thus, to calculate the fundamental solution (x, y) to Pell’s equation (1), we√either use x = x1
and y = y1 if N (n ) = 1 or equations (6) if N (n ) = −1, where n = x1 + y1 n in either case.
Thus far we have reduced the problem of solving Pell’s equation (1) to the problem of
computing the fundamental unit n of Rn and determining whether its norm is 1 or −1,
but we are still left with the problem √ of computing n . The method we use here involves
computing the continued fraction of n. We assume the reader is familiar with the general
theory of continued
√ fractions. If not, he or she can refer to [1]. As it turns out, the continued
fraction of n always has the following form:

n = [a0 ; a1 , . . . , ak−1 , ak = 2a0 ], (7)

where a0 = b nc and k is the period of the continued fraction. (The line above the coefficients
on the right indicates that they are repeated ad infinitum.) It also turns out that the (k − 1)th
rational convergent rk−1 of this continued fraction, i.e.,
rk−1 = [a0 ; a1 , . . . , ak−1 ], (8)
has reduced form√ equal to x1 /y1 . Thus if we denote the reduced form of the jth rational
convergent of n as pj /qj , then we have x1 = pk−1 and y1 = qk−1 . It also turns out that
N (n ) = 1 if and only if k is even.

√ Below we present two examples. First let us consider n = 19. In this case we have
19 = [4; 2, 1, 3, 1, 2, 8], whence k = 6 is even and hence N (n ) = 1, and thus (x1 , y1 ) is
the fundamental solution to Pell’s equation. It is straightforward to show that r5 = 170/39,
whence x1 = 170 and y1 = 39 and hence (170, 39) is the fundamental solution to Pell’s
equation for n = 19.

As our second example, consider n = 13. Here we have 12 = [3; 1, 1, 1, 1, 6], whence k = 5
is even and hence N (n ) = −1, whence (x, y) is the fundamental solution of Pell’s equation,
where x and y are given by equations (6). In this case it is straightforward to show that
r4 = 18/5, whence x1 = 18 and y1 = 5 and hence by (6) we have x = 649 and y = 180. Thus,
(649, 180) is the fundamental solution to Pell’s equation for n = 13.

References
[1] https://en.wikipedia.org/wiki/Continued fraction (Wikipedia article on continued fractions)

You might also like