counting set bits of a natural number

161 Views Asked by At

For a natural number $n$ let $f(n)$ denote the number of set bits of $n$ - which is basically the Hamming weight of the binary representation of $n$. See wiki for more info.

I have to prove that $f(n^2) = \frac{1}{2} f(n)(f(n)+1)$ for infinitely many natural numbers. Can induction help here? It holds trivially for $1$ so maybe it is a good approach, I just do not see how to generalize it to $n$ or $n+1$.

Update: Note that for $n=2^k$ for $k>0$ we have that $f(2^k)=1$ and so when we calculate $f((2k)^2) = f(2^{2k})$ which is a power of two again so it is equal to $1$ and so is $$\frac{1}{2} f(2^k)(f(2^k)+1) =1$$

1

There are 1 best solutions below

8
On BEST ANSWER

If you want to prove that for all numbers then you can use induction. But not all numbers verify this, for instance $n=3$.

You could use induction inside a set $A$ other than $\mathbb{N}$, if you suspect that all elements of this set verify your expression. In that case the inductive step will be different.

As a comment suggests, the set of all powers of 2 verify this. You can deduce directly from computations or if you really want to, induction