How this calculation works
The Pell equation seeks integer coordinates on a hyperbola. The trivial point (1, 0) always satisfies the equation, but this calculator asks for positive y and the smallest positive x. For a positive nonsquare integer D, continued fractions of √D provide an efficient route to the fundamental solution. The computation keeps numerators and denominators as exact integers, even when the smallest solution is much larger than the input.
x² − Dy² = 1; test the convergents x/y of the continued fraction of √D.A worked example
With D = 13, the fundamental solution is x = 649 and y = 180. Squaring gives 421,201 and 32,400; multiplying the second by 13 gives 421,200. Their difference is exactly one. The much smaller pair (18, 5) gives 324 − 325 = −1, so it solves the negative Pell equation rather than the requested equation.
Good to know
D must be a nonsquare integer from 2 through 10,000. This page handles norm +1 only and reports the fundamental positive solution rather than an arbitrary generalized equation x² − Dy² = N. The convergence table shows at most its first 40 rows; final metrics always contain the complete exact solution.
Reference: SymPy — generalized Pell equations (opens in a new tab) ↗
Why a small D can have a large smallest solution
For D = 13, rounding y√13 for successive small y values is a poor search strategy: the first positive solution does not appear until y = 180. Continued fractions instead provide exceptionally close rational approximations to √13. Each convergent supplies a candidate x/y, and the exact integer residual x² − 13y² decides whether it solves the equation.
The first three convergents are 3/1, 4/1 and 7/2. Their residuals are −4, 3 and −3. Continue until 649/180 gives +1. A decimal display of x/y could obscure the distinction between a close approximation and an exact solution, so the calculator always exposes the integer norm. It never accepts closeness to one as a substitute for equality.
The continued fraction calculator expands a supplied rational number. Here rational convergents instead supply candidates for an exact integer equation.
Keep the positive and negative equations separate
A norm of −1 is informative but does not satisfy this page’s equation. For D = 13, the pair (18, 5) is one such example. Squaring the algebraic number 18 + 5√13 produces 649 + 180√13, whose norm is +1. The solver continues until it reaches the requested sign rather than returning the first visually small residual.
A square input D = s² makes (x − sy)(x + sy) = 1. With positive integer x and y, the two factors cannot both be one, so no positive-y solution exists. That is why square inputs are rejected. Once a fundamental solution is known, positive powers of x + y√D generate further positive solutions. This equation problem is distinct from calculating a term of the Pell recurrence sequence, which already has its own page.
A few questions, answered
Why exclude the solution x = 1, y = 0?
It is valid but trivial and appears for every D. The purpose here is to find the fundamental solution with both coordinates positive.
Are large answers rounded?
No. The integer coordinates and the norm check use BigInt arithmetic. Long values may wrap visually, but their digits are retained.