Not One Bit More
Time limit1sMemory limit128 MB
Count integers in [LO, HI] whose repeated popcount chain reaches 1 at exactly step X, with LO up to 1e18 and X up to 10.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation, Math, Combinatorics
- Solved
- No attempts yet
Problem
Start with an integer . Let be the number of ones in the binary representation of . For example, if , then .
In general, let be the number of ones in the binary representation of . This sequence always converges to one.
For any starting number , let be the smallest index such that . For example, if , then , , , so . In particular, , since is already one.
Given a range of consecutive integers and a value , how many numbers in the range have a value equal to ?
Input
The input contains several test cases. Each test case is a single line with three integers:
LO HI X
where and () are the lower and upper limits of a range of integers, and () is the target value for .
The input ends with a line containing three zeros, which is not processed.
Output
For each test case, print a single line with one integer: the number of integers in the range (inclusive) whose value equals .