In the last lesson, the convergent $\frac{8}{3}$ of $\sqrt{7}$ satisfied $8^{2} - 7 \cdot 3^{2} = 1$. That was no accident. The equation $x^{2} - dy^{2} = 1$, named (by a historical mix-up) after John Pell, is solved completely by the continued fraction of $\sqrt{d}$.
Pell's equation. Let $d > 0$ be an integer that is not a perfect square. We want integers with $x^{2} - dy^{2} = 1$. The trivial solution is $(1, 0)$. The fundamental solution $(x_1, y_1)$ is the solution in positive integers with the smallest $y$.
Theorem. The fundamental solution always exists, and $\frac{x_1}{y_1}$ is a convergent of $\sqrt{d}$. Every solution in positive integers comes from its powers: $$x_k + y_k\sqrt{d} = \left(x_1 + y_1\sqrt{d}\right)^{k}, \qquad k = 1, 2, 3, \dots$$
Why it works
Worked example: A small search
- Try $y = 1$: $1 + 2 = 3$, not a square. $y = 2$: $1 + 8 = 9 = 3^{2}$.
- So $(x_1, y_1) = (3, 2)$. It is the convergent $\frac{3}{2}$ of $\sqrt{2} = [1; 2, 2, \dots]$.
Answer: $(3, 2)$.
Worked example: The next solution
- $(3 + 2\sqrt{2})^{2} = 9 + 12\sqrt{2} + 8 = 17 + 12\sqrt{2}$.
- So $(x_2, y_2) = (17, 12)$. Check: $289 - 2 \cdot 144 = 1$.
Answer: $(17, 12)$.
Worked example: With the continued fraction
- $\sqrt{7} = [2; \overline{1, 1, 1, 4}]$ has convergents $\frac{2}{1}, \frac{3}{1}, \frac{5}{2}, \frac{8}{3}, \dots$
- $p^{2} - 7q^{2}$ for these: $4 - 7 = -3$, $9 - 7 = 2$, $25 - 28 = -3$, $64 - 63 = 1$.
- The first $+1$ is at $\frac{8}{3}$.
Answer: $(8, 3)$.
Solutions can be startlingly large. For $d = 13$ the fundamental solution is $(649, 180)$; for $d = 61$ it is $x = 1{,}766{,}319{,}049$, $y = 226{,}153{,}980$, a challenge Fermat set for other mathematicians in 1657. A search over $y$ would take ages; the continued fraction finds it in a few dozen steps.
Common mistake
Key idea