Pell Equations
For details see my notes on Pell equations.
Suppose we wish to solve
where is not a square. First we compute the continued fraction expansion of .
Then the continued fraction expansion of is
It turns out .
The convergents are computed by
The convergents satisfy
and is the smallest integer solution of the Pell equation for odd , and if is even. From a minimal positive solution , we may generate the other positive solutions via
for all positive .
Generalized Pell Equations
Now consider the equation
If we may do the following. Compute the convergents until the smallest integer solution of the Pell equation is found. In the meantime, check if each satisfies for some . If so, append to the list of solutions.
We now use this list of solutions to generate all other solutions. If is on the list, and is a minimal positive solution of the corresponding Pell equation, then we have a family of solutions given by
for all positive .
If then one possibility is brute force. If set , otherwise set . For check if for some integer . If so, then append to the list of fundamental solutions. Also append if not equivalent to . (TODO: can avoid since we don’t want negative solutions?) Then proceed as above to generate all solutions.