6951.Counting Bits

Time Limit: 1s Memory Limit: 512MB

Your task is to count the number of one bits in the binary representations of integers between $1$ and $n$ .

Input Format(From the terminal/stdin)

The only input line has an integer $n$ .

  • $1 \le n \le 10^{15}$

Output Format(To the terminal/stdout)

Print the number of one bits in the binary representations of integers between $1$ and $n$ .

Sample Input

Copy
7
 \n

Sample Output

Copy
12
  \n

The binary representations of $1 \ldots 7$ are 1, 10, 11, 100, 101, 110, and 111, so there are a total of 12 one bits.

Source: CSES, Bitwise Operations, 1146

Submit

请先 登录

© 2025 FAQs