According to this Mathworld page as well as Wikipedia, you can solve a Pell equation by generating the continued fraction convergents for $\sqrt{N}$. I wanted to do this, so I tried writing a program to solve the following Pell equation:
$p^2 - 13q^2 = 1$
I already knew the answer off the top of my head, $p=649$ and $q=180$. This is the minimal solution in $p$. But when I ran my program, nowhere did I find the $p_n/q_n$ convergent $649/180$. Instead, I found this.
Convergents (p/q) for the square root of 13.
p[0] = 3 q[0] = 1
p[1] = 4 q[1] = 1
p[2] = 7 q[2] = 2
p[3] = 11 q[3] = 3
p[4] = 18 q[4] = 5
p[5] = 119 q[5] = 33
p[6] = 137 q[6] = 38
p[7] = 256 q[7] = 71
p[8] = 393 q[8] = 109
p[9] = 2614 q[9] = 725
I believe these are the correct convergents... I double-checked. But nowhere do I find the correct answer, $p_n/q_n = 649/180$. Could someone tell me what's wrong with my approach? Is my understanding of Pell equations a little off?