3. (1991 Japan Mathematical Olympiad) $n$ is a non-negative integer, determined by $f(0)=0, f(1)=1, f(n)=$ $f\left(\left[\frac{n}{2}\right]\right)+n-2\left[\frac{n}{2}\right]$. Find the maximum value of $f(n)$ when $0 \leqslant n \leqslant 1991$. (Here $[x]$ denotes the greatest integer not exceeding $x$)
3. Represent $n$ as a binary number: $n=\left(a_{k} a_{k-1} \cdots a_{2} a_{1}\right)_{2}$, where $a_{i}=0$ or $1, i=1,2, \cdots, k$, then $\left[\frac{n}{2}\right]=$ $\left(a_{k} a_{k-1} \cdots a_{2}\right)_{2}, f(n)=f\left(\left(a_{k} a_{k-1} \cdots a_{1}\right)_{2}\right)=f\left(\left[\frac{n}{2}\right]\right)+n-2\left[\frac{n}{2}\right]=f\left(\left(a_{k} a_{k-1} \cdots a_{2}\right)_{2}\right)+a_{1}=$ $f\left(\left(a_{k} a_{k-1} \cdots a_{3}\right)_{2}\right)+a_{2}+a_{1}=\cdots=a_{k}+a_{k-1}+\cdots+a_{2}+a_{1}$, thus $f(n)$ equals the number of digit 1s in the binary representation of $n$. Since $0<2^{10}-1<1991<2^{11}-1$, $n$ can have at most 11 binary digits, but the digits of $n$ can be 10, but cannot have 11 ones. Therefore, the maximum value of $f(n)$ is 10.