# Smallest number $N$, such that $\sqrt{N}-\lfloor\sqrt{N}\rfloor$ has a given continued fraction sequence

How can I find the smallest positive integer $N$, such that the continued fraction of $\sqrt{N}-\lfloor\sqrt{N}\rfloor$ begins with a given finite sequence containing a zero followed by positive integers ?

For example, the sequence $[0,1,2,3,4]$ is given. We have to find the smallest number $N$, such that $\sqrt{N}-\lfloor\sqrt{N}\rfloor$ begins with $[0,1,2,3,4]$.

The number $\sqrt{388}-\lfloor\sqrt{388}\rfloor$ has continued fraction $[0,1,2,3,4,12,1,\cdots]$ , so $N=388$ is a possible number (In this case, it is the smallest possible number).

The existence of a number $N$ follows from the fact that the sequence $\sqrt{2}\cdot n$ , when $n$ runs over the positive integers which are not a square, is equidistributed modulo $1$, so every rational number in the range $[0,1]$ can be approximated arbitary close, hence the continued fraction will begin with a given sequence.

But I have no idea how to find a possible number (and even better, the smallest possible number) efficiently.

Any ideas ?

• $N=3469643$ is the smallest solution for $[0,1,2,3,4,5,6]$ – Peter Jan 9 '17 at 16:37
• This number $N$ is curiously a palindrome! – Peter Jan 9 '17 at 16:46
• $N=624614708563$ is a possible solution for $[0,1,2,3,4,5,6,7,8,9]$. Is it the smallest ? – Peter Jan 9 '17 at 18:40