Colored zeros
Time limit2sMemory limit512 MB
Count how many zero bits get marked when writing 1 to n in binary and flagging every k-th zero in each row.
- Level
Hard8 of 10
- Topics
- Math, Bit manipulation, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
Толик has just learned that binary notation exists. Delighted by this, he wrote down the binary forms of the numbers 1, 2, ..., in a column. This gave the numbers 1, 10, 11, 100, 101, 110, 111, ...
After that he erased all the written ones and started studying the positions of the zeros. He chose a number and in each row, going from left to right, marked in red every -th zero, starting with the first. Thus the zeros numbered were marked. For example, if , , the rows would look like this:
(red zeros are shown in bold and underlined)
Now Толик wonders how many zeros he marked. Help him count them.
Input
The input file contains the numbers and (, ).
Output
The output file must contain one number: the number of red zeros.