Let $N$ be a positive integer not being a perfect square. Define $S:=\lfloor\sqrt{N}\rfloor$
Consider the following algorithm :
We start with the pair $[A,B]:=[S,1]$
To get the next pair we define
$$C:=\frac{N-A^2}{B}$$ $$D:=\lfloor\frac{S+A}{C}\rfloor$$
Then, define $[A,B]:=[CD-A,C]$ and repeat the procedure.
How can I prove that eventually $C=1$ will occur ?
The algorithm determines the continued fraction of $\sqrt{N}$ (The calculated $D$'s are the entries).
It is well known that the continued fraction has the form $$[S,\overline{a_1,\cdots,a_k,2S}]$$ , where $a_1,\cdots a_k$ form a palindromic sequence (which can be empty).
But I do not want to use this result, in contrary , I want to prove the pattern.
The palindromic property is not so important, but it might help to prove the pattern, what I actually want is to prove that $2S$ will occur and that the period starts immediately after $S$.
Who can help ?