Saruman's Level Up
Time limit1sMemory limit128 MB
For each N up to 10^16, count how many integers i in [1, N] have a binary digit sum that is a multiple of 3.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation, Math, Combinatorics
- Solved
- No attempts yet
Problem
Saruman's army of orcs and other dark minions mine coal and harvest lumber from the land surrounding his mighty tower every day for consecutive days. On day number , Saruman either spends resources on mining and harvesting, or on raising the level (that is, the height) of his tower. He raises his tower's level by exactly one unit only on days where the binary representation of contains a number of 1's that is an exact multiple of 3. The initial level of his tower on day 0 is zero.
For example, Saruman raises his tower's level on day 7 (binary 111), then on day 11 (binary 1011), and then on day 13, day 14, day 19, and so on.
Saruman would like to forecast the level of his tower after days. Can you write a program to help?
Input
The input contains multiple test cases, each on a single line. Each test case consists of a single positive integer (), as described above. The input ends at end of file (EOF).
Output
For each test case, output one line in the format Day N: Level = L, where is the given input and is the level of the tower after days.