Solution (source code)

= Solution

Directly,
$$
a+\frac{At+B}{Ct+D}
=\frac{(aC+A)t+(aD+B)}{Ct+D}.
$$
Thus take $\alpha=aC+A$, $\beta=aD+B$, $\gamma=C$, and $\delta=D$. They are nonnegative and
$$
\alpha\delta-\beta\gamma=AD-BC=1.
$$

Each finite block of a <continued fraction> acts by a fractional linear transformation with an integral matrix of determinant $\pm1$. If the block $a_1,\ldots,a_N$ repeats, removing one period leaves the same tail $x$, so
$$
x=\frac{Ax+B}{Cx+D}
$$
for integers $A,B,C,D$. Hence $Cx^2+(D-A)x-B=0$, with the linear case allowed when $C=0$.

For period $(a,b)$,
$$
x=a+\frac1{b+1/x},
$$
so
$$
\boxed{bx^2-abx-a=0}.
$$
The continued fraction is positive, so it is the positive root
$$
\boxed{x=\frac{ab+\sqrt{a^2b^2+4ab}}{2b}},
$$
while the other root is negative.