Skip to content

Pell's Equation and Sums of Squares

Definition. For a nonsquare positive integer DD, Pell’s equation is

x2−Dy2=1,x,y∈Z.x^2 - D y^2 = 1, \qquad x, y \in \mathbb{Z}.

The trivial solutions (±1,0)(\pm 1, 0) always exist; the equation is interesting because whenever one non-trivial solution (x1,y1)(x_1, y_1) exists, infinitely many do; all generated by powers of the fundamental solution in the ring Z[D]\mathbb{Z}[\sqrt{D}]:

xk+ykD=(x1+y1D)k,k=1,2,3,…x_k + y_k \sqrt{D} = (x_1 + y_1 \sqrt{D})^k, \qquad k = 1, 2, 3, \ldots

(the algebra works because (x12−Dy12)(x22−Dy22)=(x1x2−Dy1y2)2−D(x1y2+x2y1)2(x_1^2 - D y_1^2)(x_2^2 - D y_2^2) = (x_1 x_2 - D y_1 y_2)^2 - D(x_1 y_2 + x_2 y_1)^2; Brahmagupta’s identity).

Example. x2−2y2=1x^2 - 2y^2 = 1: fundamental solution (3,2)(3, 2), and successive solutions (17,12),(99,70),(577,408),…(17, 12), (99, 70), (577, 408), \ldots; the yy-values grow like (3+22)k/(22)(3 + 2\sqrt 2)^k / (2\sqrt 2), exponentially.

Example (the cattle problem of Archimedes, simplified). x2−61y2=1x^2 - 61 y^2 = 1 has fundamental solution x=1766319049x = 1766319049, y=226153980y = 226153980; a famously enormous answer discovered via continued fractions, illustrating why the equation resisted solution for centuries.

The continued fraction expansion of D\sqrt{D} is periodic for every nonsquare DD:

D=[a0;a1,a2,…,ar‾].\sqrt{D} = [a_0; \overline{a_1, a_2, \ldots, a_r}].

The solutions of Pell’s equation come from the convergents pk/qkp_k/q_k:

  • If the period length rr is even, (pr−1,qr−1)(p_{r-1}, q_{r-1}) is the fundamental solution of x2−Dy2=1x^2 - Dy^2 = 1.
  • If rr is odd, (p2r−1,q2r−1)(p_{2r-1}, q_{2r-1}) solves =1= 1, and (pr−1,qr−1)(p_{r-1}, q_{r-1}) solves the negative Pell equation x2−Dy2=−1x^2 - D y^2 = -1.

Worked example. 7=[2;1,1,1,4‾]\sqrt{7} = [2; \overline{1, 1, 1, 4}] (r=4r = 4, even). Convergents: 2/12/1, 3/13/1, 5/25/2, 8/38/3; check 82−7⋅32=64−63=18^2 - 7 \cdot 3^2 = 64 - 63 = 1: fundamental solution (8,3)(8, 3), and the next is (127,48)(127, 48).

Theorem (Fermat, two squares). An odd prime pp satisfies p=x2+y2p = x^2 + y^2 iff p≡1(mod4)p \equiv 1 \pmod 4; and a general integer nn is a sum of two squares iff every prime q≡3(mod4)q \equiv 3 \pmod 4 divides nn to an even power.

Proof idea of the prime case. For p≡1(mod4)p \equiv 1 \pmod 4, −1-1 is a QR (Euler’s criterion), so x2≡−1(modp)x^2 \equiv -1 \pmod p has a solution; x2+1≡0(modp)x^2 + 1 \equiv 0 \pmod p means p∣x2+1p \mid x^2 + 1 with 0<x2+1<p20 < x^2 + 1 < p^2, so by descent (repeatedly halving via a multiple of pp) a genuine representation is produced. ■\blacksquare

Examples: 5=1+45 = 1 + 4, 13=4+913 = 4 + 9, 17=16+117 = 16 + 1, 29=25+429 = 25 + 4 (p≡1 mod 4p \equiv 1 \bmod 4); while 3,7,11,19≡3 mod 43, 7, 11, 19 \equiv 3 \bmod 4 are never sums of two squares. 21=3⋅721 = 3 \cdot 7 has 3 to an odd power → not a sum of two squares. 45=32⋅545 = 3^2 \cdot 5 → 45=36+945 = 36 + 9 ✓ (3 appears to an even power).

Lagrange’s four-square theorem: every n≥0n \geq 0 is a sum of four squares (proven by Euler’s identity plus descent). Waring’s theorem generalises: every nn is a sum of at most g(k)g(k) kk-th powers; the conjectured values g(2)=4g(2) = 4, g(3)=9g(3) = 9, g(4)=19g(4) = 19 are known.

Two squares → at most four squares → the pattern of which numbers need how many squares is governed by Legendre’s three-square theorem: nn is a sum of three squares iff nn is not of the form 4a(8b+7)4^a(8b + 7).

  • Pell has no solutions when DD is a perfect square (x2−k2y2=1x^2 - k^2 y^2 = 1 factors over Z\mathbb{Z}, forcing y=0y = 0).
  • The fundamental solution can be astronomically large (D=61D = 61 case); never guess it; use the continued fraction of D\sqrt{D}.
  • The two-squares criterion fails on the power of a 3 mod 43 \bmod 4 prime: 9=329 = 3^2 is not a sum of two squares (odd power test), but 9⋅5=459 \cdot 5 = 45 is.
  • Products of sums of two squares are again sums of two squares (Brahmagupta); quotable in constructions.
xk+ykD=(x1+y1D)kx_k + y_k \sqrt{D} = (x_1 + y_1 \sqrt{D})^k

Generate Pell solutions by repeated multiplication in Z[D]\mathbb{Z}[\sqrt{D}]: for D=2D = 2, (3+22)2=17+122(3 + 2\sqrt2)^2 = 17 + 12\sqrt2, so the next solution is (17,12)(17, 12). Quote Brahmagupta’s identity as the reason powers of one solution are again solutions. Check every Pell solution by substitution before quoting it: x2−Dy2x^2 - Dy^2 must equal exactly 1, and one arithmetic slip in a large multiplication invalidates the whole sequence.

For D=5D = 5: 5=[2;4‾]\sqrt5 = [2; \overline{4}], period 1 (odd), so (9,4)(9, 4) solves x2−5y2=1x^2 - 5y^2 = 1 from the convergent 9/49/4, and (2,1)(2, 1) solves x2−5y2=−1x^2 - 5y^2 = -1.