After Bob had won a game of chess against the King, he had asked the King to give him $\sum_{i=0}^{63}2^i$ grains of rice as a reward.
"What? I'm not an idiot."
Instead, the King proposes to play another game to decide on the number of rice grains he rewards Bob.
The King lays down $r-l+1$ piles of rice grains, where the first pile has $l$ grains, the second pile has $l+1$ grains...
and the $(r-l+1)$-th pile has $r$ grains.
A round of the game is as follows:
- If it has an odd number of grains, Bob takes 1 grain from the pile.
- Else if it has an even number of grains, the King takes half of the grains from the pile.
Bob is unsure how many grains of rice would be rewarded to himself, so he turns to you!
Input
The first and only line contains two integers: $l$, $r$.
Output
Output one integer: the number of rice grains that Bob would be rewarded with.
Constraints
For all subtasks:
- $1 \le l \le r \le 10^{15}$
Subtask 1 (15%): $l=r$
Subtask 2 (25%): $r-l+1 \le 10^6$
Subtask 3 (30%): $l=1, r=2^x-1$
Subtask 4 (30%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
3 7 | 10 | |
17 49 | 100 |
Scoring: Per Subtask
Authored by s19x17
Appeared in 2023 Mini Contest 5 (JSOI Selection)