Firmware sectors are addressed by consecutive integers from L to R inclusive. For auditing, you must count the total number of 1 bits that appear across the binary representations of all sector addresses in this range.
Formally, compute the sum, over every integer v with L <= v <= R, of the number of set bits in v.
Line 1: two space-separated integers L and R.
A single integer: the total number of set bits over all integers in [L, R].
Example 1
Input
2 5
Expected
6
Explanation
2=10 (1), 3=11 (2), 4=100 (1), 5=101 (2); total 1+2+1+2 = 6.
Example 2
Input
0 0
Expected
0
Explanation
Only 0, which has no set bits.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →