Count the Bits
InterviewTime limit2sMemory limit512 MB
Given k and b, count the total number of 1-bits in all multiples of k from 0 to 2^b-1, and print the sum modulo 10^9+9.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation, Math
- Solved
- No attempts yet
Problem
Given a value and a number of bits , calculate the total number of 1-bits in the binary representations of all multiples of that are between and (inclusive).
Input
Each input consists of a single test case. Your program may be run multiple times on different inputs.
Each test case consists of a single line containing two space-separated integers () and (), where and are as described above.
Output
Output a single integer, the total number of 1-bits in the binary representations of all multiples of that are between and (inclusive). Since this number may be very large, output it modulo .
Hint
Consider the second sample: and .
. All the multiples of between and are , and .
- (2 1-bits)
- (2 1-bits)
- (4 1-bits)
That is a total of 1-bits.