Hi, you'll have to learn how to calculate square roots with continued fractions.

Since formatting continued fractions is a nightmare of parentheses, I'll refer you to Continued Fraction -- from Wolfram MathWorld and ask you to read equation (3), which gives the basic form of the continued fractions we'll need and the shortcut form for this (4) so I don't scratch my eyeballs out trying to format things. Also see (11) for the finite version of this. Another bit of slightly confusing notation, [x] will mean the greatest integer less than x. This shouldn't be confused with our continued fraction notation, since that will always have more than one term.

Assume D is not a perfect square. To find the continued fraction expression of , we first set . This is a very crude approximation to \sqrt{D}. At this point we have

We apply the same procedure to

Now we have

Now . Continue to get the rest of the a's. Eventually you'll get something that repeats like

Heres where you stop. If k is odd find integers x and y where . These are your minimal solutions to Pell's equation. If k is even, you do something similar, I'm not positive exactly what, sorry. I'll hopefully come back tomorrow with an answer.

An example: D=14

so

So

So

ok I'm stopping here. Go a couple more steps and you'll get so we've started to repeat.

Now find , so x=15 and y=4 are the minimal solutions in this case.