Let $d>1$ be not a square. Then the continued fraction expansion of $\sqrt d$ is $[a\_0; \overline{a\_1,\dots,a\_\ell}]$, where $a\_0=\lfloor \sqrt d\rfloor$ and $a\_\ell=2a\_0$.
Thus, $\ell=\ell(d)$.


About 30 years ago I heard a talk where $\ell(d)$ was somehow related to the class number of $\mathbb Q(d)$ -- in particular, to [the Gauss class number problem](https://en.wikipedia.org/wiki/Class_number_problem) which conjectures that there are infinitely many natural $d$ for which class number is 1.


Unfortunately, I don't remember how to restate this conjecture via $\ell(d)$. Any reference would be helpful.



Period of continued fraction expansion and class number
Claude Levesque, [On semi-reduced quadratic forms, continued fractions and class number](https://www.kurims.kyoto-u.ac.jp/%7Ekyodo/kokyuroku/contents/pdf/0998-7.pdf), quotes a theorem of Lu, H., On the class number of real quadratic fields, Scientia Sinica II (special number, 1979), 118-130, as follows:


Let $m>1$ be a squarefree integer. Then the class number of ${\bf Q}(\sqrt m)$ is one if and only if $$\theta+\sum\_{i=1}^{\ell}k\_i=\lambda\_1(m)+\lambda\_2(m)$$ where $\omega=(1+\sqrt m)/2$ if $m\equiv1\bmod4$, otherwise $\omega=\sqrt m$, the continued fraction for $\omega$ is $[k\_0,\overline{k\_1,\dots,k\_{\ell}}]$, $\theta$ is zero, one, or two depending on $m\bmod4$ and the parity of $\ell$ and $k\_{\ell/2}$, and $\lambda\_1(m)$ (respectively, $\lambda\_2(m)$) is the number of solutions in nonnegative integers of $x^2+4yz=\Delta$ (respectively, $x^2+4y^2=\Delta$), where $\Delta$ is $m$ if $m\equiv1\bmod4$, otherwise $4m$.


For the detailed definition of $\theta$, see the paper of Levesque. The paper goes on to prove related results.


Another paper that may be relevant is Louboutin, Mollin, & Williams, Class Numbers of Real Quadratic Fields, Continued Fractions, Reduced Ideals, Prime-Producing Quadratic Polynomials and Quadratic Residue Covers, Canadian Journal of Mathematics 44 (1992) 824-842. DOI:10.4153/CJM-1992-049-0.


