20. For any positive integer $n$, let $f(n)$ denote the index of the highest power of 2 which divides $n!$, e.g. $f(10)=8$ since $10!=2^{8} \times 3^{4} \times 5^{2} \times 7$. Find the value of $f(1)+f(2)+\cdots+f(1023)$.
(3 marks)
對於任何正整數 $n$, 設 $f(n)$ 為可整除 $n$ ! 的 2 的最高乘冪的指數。例如：因為 $10!=2^{8} \times 3^{4} \times 5^{2} \times 7$, 所以 $f(10)=8$ 。求 $f(1)+f(2)+\cdots+f(1023)$ 的值。
20. 518656
20. The key observation is that $f(n)=n-g(n)$, where $g(n)$ is the number of 1 's in the binary representation of $n$. To see this, it suffices to check that for non-negative integers $a_{1}<a_{2}<\cdots<a_{k}$ and $n=2^{a_{1}}+2^{a_{2}}+\cdots+2^{a_{k}}$, we have
$$
\left[\frac{n}{2}\right]+\left[\frac{n}{2^{2}}\right]+\cdots+\left[\frac{n}{2^{a_{k}}}\right]=n-k
$$

Such checking is straightforward.
Next we try to compute $g(0)+g(1)+\cdots+g(1023)$. Note that the binary representations of 0 and 1023 are respectively 0000000000 and 1111111111 , so as $n$ runs through 0 to $1023, g(n)$ is equal to 5 'on average'. Since $g(0)=0$, we have
$$
g(1)+\cdots+g(1023)=5 \times 1024=5120 .
$$

Now we have
$$
\begin{aligned}
f(1)+f(2)+\cdots+f(1023) & =(1+2+\cdots+1023)-[g(1)+g(2)+\cdots+g(1023)] \\
& =\frac{1023 \times 1024}{2}-5120 \\
& =512 \times(1023-10) \\
& =518656
\end{aligned}
$$