Pell Equation Calculator

Equation x^2 - D y^2 = 1

Minimal solution (x, y)(3, 2)
Check x^2 - D y^21
Continued fraction period of sqrt(D)1
x value3
y value2
How this was calculated
  1. The Pell equation x^2 - 2 y^2 = 1 is solved by the continued fraction of sqrt(2), whose repeating period here has length 1.
  2. The period is odd, so the convergent at the end of the second period gives the minimal solution x = 3, y = 2.
  3. Substitution confirms it: 3^2 - 2 x 2^2 = 1, exactly 1 as the Pell equation requires.
  4. Minimal solutions can explode with D: D = 61 already needs x = 1,766,319,049, the result that famously challenged Fermat's contemporaries - all solutions then follow by raising the minimal one to powers.

A pell equation calculator solves equations of the form x^2 - D y^2 = 1 for whole-number values of x and y. This page takes your value of D and finds the minimal solution, the smallest positive pair that satisfies the equation. For non-square D, solutions always exist, and every other solution grows from that minimal one. The results can be surprising: for D = 2 the minimal solution with y above 0 is (3, 2), since 9 - 8 = 1. For D = 7 the minimal solution is (8, 3), and substituting back into the equation gives exactly 1. For D = 13 the minimal solution is (649, 180), found from the period 5 continued fraction of sqrt(13). For D = 61 the minimal x is 1,766,319,049, the case Fermat used to challenge his contemporaries.

The calculator relies on continued fractions, the accepted standard method for this kind of calculation. The continued fraction of sqrt(D) is periodic, and its convergents supply the solutions. If the period length is odd, the convergent at the end of the second period gives the solution. This approach finds the minimal solution directly rather than searching through candidate pairs one by one, which matters when the answer is as large as it is for D = 61. On this page you will find the formula, step-by-step workings, worked examples and sources, so you can follow how each answer is produced and check it yourself.

Worked examples

D = 2, the oldest example

(2)

Minimal solution (x, y)(3, 2)
Check x^2 - D y^21
Continued fraction period of sqrt(D)1
x value3
y value2

D = 7

(7)

Minimal solution (x, y)(8, 3)
Check x^2 - D y^21
Continued fraction period of sqrt(D)4
x value8
y value3

D = 13, a larger minimal solution

(13)

Minimal solution (x, y)(649, 180)
Check x^2 - D y^21
Continued fraction period of sqrt(D)5
x value649
y value180

An equation older than its name

The equation x^2 - D y^2 = 1 is named for John Pell, but Pell had nothing to do with it. The misattribution traces to Euler, who credited Pell with a method that actually belonged to others. The mathematics is far older than the name. For any non-square D the equation always has solutions, and every solution grows out of the smallest one — a fact that made the problem both tractable and, in stubborn cases, famously hard.

Indian mathematicians had solved it centuries before Europe took it up. Brahmagupta and later Bhaskara II developed the chakravala method, a cyclic procedure for producing solutions to x^2 - D y^2 = 1. Their work showed that the equation is not a curiosity but a structured problem with a systematic route to its minimal solution. A pell equation calculator today reaches the same answers through continued fractions, but the underlying goal — find the smallest x and y — is unchanged.

Small values of D give a sense of the scale. For D = 2 the minimal solution with y above 0 is (3, 2), since 9 - 8 = 1. For D = 7 the minimal solution is (8, 3), and substituting back into the equation gives exactly 1. For D = 13 the minimal solution is (649, 180), found from the period 5 continued fraction of sqrt(13). The continued fraction of sqrt(D) is always periodic, and when the period length is odd, the convergent at the end of the second period gives the solution.

Then there is D = 61, the case Fermat used to challenge his contemporaries. Its minimal x is 1,766,319,049 — a number large enough that searching by hand is hopeless, which was precisely Fermat's point. The challenge helped push European mathematicians toward general methods rather than case-by-case cleverness.

The history matters because it explains the name on the page. A pell equation calculator carries the label Euler gave it, but the method behind the answer descends from chakravala and from the continued fraction of sqrt(D). The minimal solution is always the seed; everything else follows from it.

The equation is called Pell's, but Euler's attribution honored the wrong person — the chakravala method of Brahmagupta and Bhaskara II came first.

Continued fractions do the work

The continued fraction of the square root of D is the engine behind most serious methods for solving the Pell equation, and it is what a pell equation calculator computes when you ask it for the minimal solution. For any non-square D, the expansion of sqrt(D) is periodic: it begins with a whole-number part and then repeats a fixed block of terms forever. That repeating block is the key. Its length, called the period, controls which convergent you need to read off as your answer.

Convergents are the fractions you get by cutting the continued fraction off at each stage. Each convergent p/q is the best rational approximation to sqrt(D) with that size of denominator, and the Pell equation is really a question about how well such fractions can approximate sqrt(D). Because the expansion repeats, the convergents follow a repeating pattern too, and at certain points the quantity p^2 - D q^2 lands exactly on 1. Small cases show the pattern clearly. For D = 2 the minimal solution with y above 0 is (3, 2), since 9 - 8 = 1. For D = 7 the minimal solution is (8, 3), and substituting back into the equation gives exactly 1.

The even-versus-odd rule decides which convergent to take. If the period length of the continued fraction of sqrt(D) is even, the convergent at the end of the first period already solves the equation. If the period length is odd, that first-period convergent does not give 1, and you must go one step further: the convergent at the end of the second period gives the solution. This is why the period length matters so much in practice, and why a calculator that reports the period alongside the answer is more useful than one that only prints the pair of numbers.

D = 13 is a good illustration of the odd-period case. Its continued fraction has period 5, an odd length, so the first-period convergent falls short and the solution comes from the end of the second period: (649, 180). The numbers grow quickly as D increases, which is why doing this by hand is painful and why the calculator exists.

Once the minimal solution is known, everything else follows from it. For non-square D the equation always has solutions, and all of them grow from the minimal one, so the minimal pair is the seed for the entire family. The growth can be startling. For D = 61 the minimal x is 1,766,319,049, the case Fermat used to challenge his contemporaries, and a reminder that a modest-looking D can hide an enormous answer. A continued-fraction approach finds it without any guessing.

Rule of thumb: even period length means the end of the first period solves it; odd period length means you must go to the end of the second period.

Checking the answers

Any result from a pell equation calculator should be checked the simplest way possible: put the numbers back into x^2 - D y^2 and see whether the answer is exactly 1. This is the whole test. If the left side comes out to 1, the pair is a genuine solution; if it comes out to anything else, the pair is wrong, no matter how it was produced. Checking costs one multiplication and one subtraction, and it works for every D, including the small cases where a mistake is easiest to spot.

For D = 2 the minimal solution with y above 0 is the pair (3, 2). Substituting: x^2 is 9 and D y^2 is 2 times 4, which is 8. Then 9 - 8 = 1, so the pair passes. For D = 7 the minimal solution is (8, 3). Here x^2 is 64 and D y^2 is 7 times 9, which is 63. Substituting back into the equation gives exactly 1. Both of these are small enough to verify in your head, which makes them good first examples to run through a calculator before trusting it on larger inputs.

The D = 13 case is a better stress test because the numbers are no longer tiny. The minimal solution is (649, 180), found from the period 5 continued fraction of sqrt(13). Checking it takes a little more arithmetic: 649^2 is 421,201, and 180^2 is 32,400, so 13 times 32,400 is 421,200. The difference is 421,201 - 421,200 = 1. The pair passes exactly, and it also shows why the continued fraction method is used — the answer is far too large to guess, yet the check is still a single subtraction.

These three checks also illustrate the larger structure. The Pell equation x^2 - D y^2 = 1 always has solutions for non-square D, and all of them grow from the minimal one, so a correct minimal pair is the seed for every later solution. The continued fraction of sqrt(D) is periodic, and when the period length is odd, the convergent at the end of the second period gives the solution. That is the mechanism behind the D = 13 result and behind the other examples.

Size is no protection against error, which is why the substitution check matters most on the big cases. For D = 61 the minimal x is 1,766,319,049 — the case Fermat used to challenge his contemporaries. A pair that large is easy to mistype and hard to eyeball, but it still has to satisfy x^2 - 61 y^2 = 1 exactly. Whatever a pell equation calculator reports, substitute it back: the only acceptable outcome is 1.

  • D = 2, pair (3, 2): 9 - 2(4) = 9 - 8 = 1
  • D = 7, pair (8, 3): 64 - 7(9) = 64 - 63 = 1
  • D = 13, pair (649, 180): 421,201 - 13(32,400) = 421,201 - 421,200 = 1
The check is always the same: substitute x and y into x^2 - D y^2. A correct solution gives exactly 1 — nothing else counts.

Generating all solutions

Once you have the minimal solution to x^2 - D y^2 = 1, you have the seed for infinitely many more. Every solution is a power of the minimal one in the ring where numbers of the form x + y√D live: multiply the minimal solution by itself, and the result is another solution; multiply again, and again, without end. A pell equation calculator leans on exactly this fact, because it means the hard work is finding the smallest solution — after that, the rest are generated rather than searched for.

The smallest solution is not always small. For D = 2 the minimal solution with y above 0 is (3, 2), since 9 - 8 = 1. For D = 7 the minimal solution is (8, 3), and substituting back into the equation gives exactly 1. But the pattern can jump sharply: for D = 13 the minimal solution is (649, 180), found from the period 5 continued fraction of sqrt(13). And for D = 61 the minimal x is 1,766,319,049 — the case Fermat used to challenge his contemporaries, precisely because the answer looks so far out of reach for such a modest-looking equation.

The continued fraction of sqrt(D) is periodic, and that periodicity is the engine behind the search. If the period length is odd, the convergent at the end of the second period gives the solution. This is why the method scales to cases like D = 61 where trial and error would never finish: the calculator follows the period rather than testing candidate values one by one.

These solutions also sit inside a broader story about Diophantine approximation — how closely irrational numbers can be approximated by fractions. A solution to x^2 - D y^2 = 1 rearranges to show that x/y is a very good rational approximation to sqrt(D), with an error that shrinks as the solutions grow. The successive powers of the minimal solution therefore hand you an endless supply of increasingly accurate fractions, which is why Pell equations appear wherever mathematicians study how well quadratic irrationals can be pinned down by rationals.

  • D = 2: minimal solution (3, 2), since 9 - 8 = 1.
  • D = 7: minimal solution (8, 3), which gives exactly 1.
  • D = 13: minimal solution (649, 180), from the period 5 continued fraction of sqrt(13).
  • D = 61: minimal x is 1,766,319,049, the case Fermat used to challenge his contemporaries.
Every solution grows from the minimal one: find the smallest solution once, and the powers of it produce all the rest.

FAQs

What is the smallest solution for D = 2?

Excluding the trivial (1, 0), it is x = 3, y = 2: 3^2 - 2 x 2^2 = 1. So the smallest positive solution for D = 2 is the pair (3, 2), and plugging those values into the equation confirms the result exactly: 9 minus 8 equals 1.

Why does D = 13 jump to (649, 180)?

Its continued fraction period is 5, which is odd, so the solution comes from the second period's convergent and is much larger than D = 7's (8, 3). An odd period length pushes the fundamental solution out to a later convergent, which is why D = 13 gives (649, 180) instead of a small pair.

What happens if D is a perfect square?

There is no solution with y above 0: the left side factorises, and the calculator reports this instead of a number. When D is a perfect square, x^2 - D y^2 can be factored, so the equation cannot hold with positive y, and the calculator tells you that rather than returning a solution.

How are further solutions generated?

Raise the minimal solution: if x + y sqrt(D) is the fundamental unit, its powers give every solution in order. So once the smallest solution is found, squaring, cubing and so on produce the rest, each power yielding the next valid pair in sequence.

Is the Pell equation used anywhere practical?

It underlies rational approximations of square roots, some cryptography constructions and the theory of quadratic forms. Beyond being a classic number theory exercise, the equation connects to how square roots are approximated by fractions and to structures studied in quadratic forms and certain cryptographic schemes.

Why exact integer arithmetic?

Solutions explode combinatorially, as D = 61 shows with x = 1,766,319,049; floating point would lose the exactness the check x^2 - D y^2 = 1 requires. Working in exact integers keeps every digit correct, so the final verification of the equation is reliable even for very large solutions.

Sources

Related calculators

Continued Fraction Calculator
Expand a decimal into its continued fraction and read off the convergents — the best possible rational approximations, from 22/7 up to the legendary 355/113 for pi.
Frobenius Coin Problem Calculator
Find the largest amount that cannot be formed with two coin denominations: the Chicken McNugget theorem value ab - a - b, the count of non-representable amounts, and a representability test for any amount, with the non-coprime case handled.
Josephus Problem Calculator
Solve the Josephus problem for any circle size and elimination step: the survivor's position by the classic recurrence, with the closed form shown for step 2 and the first eliminated position.
Modular Arithmetic Calculator
Modular arithmetic calculator: remainders, addition, subtraction, multiplication, powers and inverses modulo m, with the check.