Let $d\ge 2$ and let 
$$
\sqrt d =[a\_0; \overline{a\_1,\dots, a\_\ell, 2a\_0}]
$$
be its continued fraction expansion. Clearly, if $d=n^2+1$, then $\ell=0$, which gives the lower bound for $\ell$. 


**Question.** What is the best known upper bound for $\ell=\ell(d)$ as a function of $d$?


For instance, $\ell(d)=O(d)$ is fairly trivial, following from the well-known algorithm (see [Rockett-Szusz], for instance). However, I suspect something like $O(\sqrt d)$ (or $O(\sqrt d\log d$) must be known. 



An upper bound for the length of the continued fraction expansion of $\sqrt d$
It is known that $\ell(d)=O(\sqrt{d}\log d)$ and $\ell(d)=\Omega(\sqrt{d}/\log\log d)$. 


See [Cohn's paper](http://projecteuclid.org/euclid.pjm/1102811631) (free access) for more details. 


For numerical results and some further historical comments see [Williams's paper](http://www.jstor.org/stable/2007664).


