Show that the simple continued fraction of $\sqrt{d^2-1}$ is $[d-1; \overline{1, 2d-1}]$ for $d \geq 2$ Show that the simple continued fraction of $\sqrt{d^2-1}$ is $[d-1; \overline{1, 2d-1}]$ for $d \geq 2$ 
For some reason I keep getting the wrong answers. I think it's because I am not setting my initial values correctly. What are $q_0, p_0, q_1, p_1$?
 A: Terms of the Continued Fraction
Since $\left\lfloor\sqrt{d^2-1}\right\rfloor=d-1$, the first term is $d-1$. Subtracting $d-1$ and inverting gives
$$
\frac1{\sqrt{d^2-1}-(d-1)}=\frac{\sqrt{d^2-1}+(d-1)}{2d-2}\tag{1}
$$
The floor of the term on the right is $1$; so the next term is $1$. Subtracting $1$ and inverting gives
$$
\frac{2d-2}{\sqrt{d^2-1}-(d-1)}=\sqrt{d^2-1}+(d-1)\tag{2}
$$
The floor of the term on the right is $2d-2$, so the next term is $2d-2$.  Subtracting $2d-2$ and inverting, we get back to $(1)$. Thus, the continued fraction for $\sqrt{d^2-1}$ is
$$
\left\{d-1;\overline{1,2d-2}\right\}\tag{3}
$$

Approximants Example
To compute the approximants for the continued fraction of $\sqrt{15}$, use $d=4$. As computed above, the continued fraction is $\left\{3;\overline{1,6}\right\}$:
$$
\begin{array}{r|rr|rr}
c_n&&&3&1&6&1&6&1&6\\\hline
p_n&0&1&3&4&27&31&213&244&1677\\
q_n&1&0&1&1&7&8&55&63&433
\end{array}
$$
where $p_n=c_np_{n-1}+p_{n-2}$ and $q_n=c_nq_{n-1}+q_{n-2}$ .
A: I think it should be $[d-1;\overline{1,2d-2}],$ in other words replace your $2d-1$ by $2d-2.$ Doing this works in the case of $d=2.$ 
$1+1/x$ where $x=1+1/(2+x)$ which gives $x=(1-\sqrt{3})/2$ then $1+1/x=\sqrt{3}.$
I believe in the case of any integer squareroot the period starts immediately after the initial integer part of the radical, and that the last term of the repeating part is always twice the integer part.
