Solve x² − Dy² = 1 for a positive nonsquare integer D. Find the fundamental pair and successive exact solutions. Your inputs stay in your browser.
Enter the Pell equation
x² − D·y² = 1
D may be from 2 through 10,000,000 and cannot be a perfect square. Commas, spaces, or underscores may group its digits in threes.
Fundamental and successive solutions
Your result will appear here.
For D = 13, select Solve equation to find the fundamental solution (649, 180), its continued-fraction working, and later positive pairs.
What is Pell’s equation?
The standard Pell equation asks for integer pairs (x, y) satisfying:
x² − Dy² = 1
Here D is a fixed positive integer that is not a perfect square. Every such D has infinitely many solutions. This solver lists the nontrivial positive pairs with x > 1 and y > 0.
The two trivial solutions (1, 0) and (−1, 0) always exist. Because the variables are squared, every listed positive pair also represents the four signed pairs (x, y), (x, −y), (−x, y), and (−x, −y).
How continued fractions find the fundamental solution
Set a0 = ⌊√D⌋ and expand √D into a periodic simple continued fraction.
Build exact convergents pk/qk with the standard two-term recurrence.
If the period length L is even, use L total terms; if L is odd, use 2L total terms.
The resulting pair (p, q) is the fundamental positive solution (x1, y1).
Convergent recurrence
p₋₂ = 0, p₋₁ = 1 q₋₂ = 1, q₋₁ = 0
pₖ = aₖpₖ₋₁ + pₖ₋₂ qₖ = aₖqₖ₋₁ + qₖ₋₂
Every step uses integer arithmetic. The tool verifies the final identity directly instead of relying on a decimal approximation to √D.
Generating every later solution
Once the fundamental positive solution (x1, y1) is known, all positive solutions come from powers of x1 + y1√D:
xₙ + yₙ√D = (x₁ + y₁√D)ⁿ
xₙ₊₁ = x₁xₙ + D·y₁yₙ
yₙ₊₁ = x₁yₙ + y₁xₙ
The recurrence avoids floating-point square roots and keeps arbitrarily large displayed results exact with JavaScript BigInt.
Worked example: D = 13
Continued fraction
√13 = [3; overline{1, 1, 1, 1, 6}]
The period length is 5, which is odd, so the fundamental +1 solution uses two periods, or 10 continued-fraction terms in total.
Fundamental solution
The required convergent is 649/180, giving:
649² − 13(180²) = 421,201 − 421,200 = 1
The next positive pair is (842,401, 233,640), obtained from (649 + 180√13)².
Inputs, square values, and output limits
Case
How the solver handles it
D nonsquare, 2–10,000,000
Calculates the full period, fundamental pair, and requested positive solutions exactly.
D is a perfect square
Stops with an explanation. In that degenerate case, factoring shows that only the trivial pairs (±1, 0) solve the +1 equation.
D ≤ 1 or above the limit
Rejects the value before calculation to keep browser work predictable.
Exceptionally large solution text
Stops the on-page sequence at a 120,000-character budget and reports how many exact pairs were rendered.
This tool solves the standard +1 Pell equation only. Generalized equations x² − Dy² = N need additional solvability tests and can have several unrelated families of solutions.
Pell equation FAQ
Does every nonsquare D have a solution?
Yes. Every positive nonsquare integer D has infinitely many integer solutions to x² − Dy² = 1. The smallest pair with x > 1 and y > 0 is called the fundamental solution.
Why are perfect squares excluded?
If D = k², then (x − ky)(x + ky) = 1. Integer factors force y = 0 and x = ±1, so there is no infinite nontrivial Pell sequence.
What does the continued-fraction period length change?
An even period reaches the fundamental +1 solution after one period. An odd period first corresponds to the negative equation and needs two periods to reach the +1 solution.
Are the listed pairs all integer solutions?
The table lists positive nontrivial pairs in increasing order. Apply either sign independently to x and y, and include (±1, 0), to obtain every integer solution of the standard equation.
Why can the fundamental solution be unexpectedly large?
The size is controlled by the continued fraction of √D, not simply by the size of D. For example, D = 61 already has the fundamental pair (1,766,319,049, 226,153,980).
Does this tool solve x² − Dy² = −1 or another N?
No. The negative and generalized Pell equations have different existence rules. This calculator deliberately fixes the right-hand side at +1.
Are my inputs private?
Yes. The continued-fraction expansion and BigInt recurrences run entirely in your browser. The tool does not upload, store, or place D in the page URL.