The function $f$ is defined on the set of positive integers by $$f(1) = 1,$$ $$f(2n) = 2f(n),$$ $$nf(2n + 1) = (2n + 1)(f(n) +n), n \geq 1$$
i) Prove that $f(n)$ is always an integer.
ii) For how many positive integers less than 2007 is $f(n) = 2n$ ?
For the first part, the answer key said that we can define a new variable of $g(n)=\frac{f(n)}{n}$ and this shows by induction that all $f(n)$ are integers. But for the second part, we are required to guess that $g(n)$ counts the number of $1$s in the binary notation of $n$. Does anyone know what the motivation for this is or any other more natural way to solve part (ii)?