I'm trying to prove the following:
$$\sum_{i=1}^{n} \max\left\{k\in\mathbb {N} \left| \frac{i}{2^k}\in\mathbb{N} \right.\right\}=n-1 \\ \text{where}\ n=2^x,\, x\in\mathbb{N}$$
If I write down the values of $k$ in the sequence for say $n=32$ , I get $$\langle 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5\rangle$$
which do sum up to $31$. I also know that there are sixteen $1$s, four $2$s, two $3$s, one $4$, and one $5$.
However, I'm having trouble proving it. I had an idea including inclusion & exclusion principle but that didn't work that well. Any ideas?
Since $n = 2^x$, $$\sum_{i=1}^n \max\{k\in\mathbb{N}: \frac{i}{2^k}\in\mathbb{N}\} = \sum_{i=1}^\infty\left\lfloor \frac{n}{2^i}\right\rfloor = \sum_{i=1}^\infty\left\lfloor 2^{x-i}\right\rfloor = \sum_{i=1}^x 2^{x-i} = \frac{2^x-1}{2-1} = n-1 $$ where the first equality follows from combinatorics.
Because we can interpret the first sum as the biggest number $k$ such that $2^k$ divides $n!$, and we already have Legendre's formula.