Counting Ones in a Range
InterviewTime limit1sMemory limit128 MB
Add up the number of 1 bits in the binary form of every integer from A to B.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Problem
You are given two natural numbers and . Write every integer with in binary, count the 1 digits in each one, and add all of those counts together.
Let be the number of 1 digits in the binary representation of . Compute the value below.
Input
The first line contains two natural numbers and , separated by a space. ()
Output
Print the sum of the 1 counts on the first line.