Continued Fraction Expansion of Irrational Square Root

Theorem
Let $$n \in \Z$$ such that $$n$$ is not a square.

Then the continued fraction expansion of $$\sqrt n$$ is of the form:
 * $$\left[{a_1 \left \langle{b_1, b_2, \ldots, b_{m-1}, b_m, b_{m-1}, \ldots, b_2, b_1, 2 a_1}\right \rangle}\right]$$

or
 * $$\left[{a_1 \left \langle{b_1, b_2, \ldots, b_{m-1}, b_m, b_m, b_{m-1}, \ldots, b_2, b_1, 2 a_1}\right \rangle}\right]$$

where $$m \in \Z: m \ge 0$$.

That is, it has the form as follows:
 * It is periodic;
 * It starts with an integer $$a_1$$;
 * Its cycle starts with a palindromic bit $$b_1, b_2, \ldots, b_{m-1}, b_m, b_{m-1}, \ldots, b_2, b_1$$ or $$b_1, b_2, \ldots, b_{m-1}, b_m, b_m, b_{m-1}, \ldots, b_2, b_1$$ which may be of length zero;
 * Its cycle ends with twice the first partial quotient.

Examples
$$ $$ $$ $$ $$ $$ $$ $$ $$