8. For how many integers $n$ between 1 and 2021 does the infinite nested expression
$$
\sqrt{n+\sqrt{n+\sqrt{n+\sqrt{\cdots}}}}
$$
give a rational number?
Solution. Denote the expression by $x$. Then $x^{2}=n+x$ so $x^{2}-x-n=0$ and
$$
x=\frac{1 \pm \sqrt{1+4 n}}{2} .
$$

This is rational if $1+4 n=m^{2}$ or $4 n=(m-1)(m+1)$. Hence $m$ can be any odd number with $5 \leq m^{2} \leq 8085$, i.e., $3 \leq m \leq 89$ (note $90^{2}=8100>8085$ ). There are 44 such values of $m$, corresponding to 44 values of $n$.