#K88327. Total Hamming Weight Sum
Total Hamming Weight Sum
Total Hamming Weight Sum
Given a non-negative integer \( n \), your task is to compute the total number of '1' bits (also known as the Hamming weight) in the binary representations of all integers from \( 0 \) to \( n \) inclusive.
For example, if \( n = 5 \), the binary representations are:
- 0: 0 (0 ones)
- 1: 1 (1 one)
- 2: 10 (1 one)
- 3: 11 (2 ones)
- 4: 100 (1 one)
- 5: 101 (2 ones)
Thus, the total number of ones is \(0+1+1+2+1+2=7\). Please note that if \( n = 0 \), the output should be \( 0 \).
inputFormat
The input contains a single non-negative integer \( n \) provided through standard input. \( n \) satisfies \( 0 \leq n \leq 10^9 \).
outputFormat
Output a single integer which is the total count of '1' bits in the binary representations of all integers from \( 0 \) to \( n \) inclusive.
## sample5
7