
Test
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.

I figured out what to do when k is even. I knew it involved doubling the period or something similar, but it wasn't working out. Sorry for the confusion.
Anyhoo, ionce you get to and k is even, you need to find x, y with , then x, y are your minimal solutions.
The term shouldn't be suprising. If you were at , , and you wanted to find more terms, you'd see . Muck about with a few examples and you'll see why this is so.

Glad it worked for you.
If you truncate after the first period you get .
If you try D=10, you'll get If you take x/y=3/1 then you get
but if you go to , you get:
Notice , this is no accident! You can get the rest of the solutions to Pell's either by finding more periods of your continued fraction or by finding powers of your minimal solution.