atcoder#ARC129A. [ARC129A] Smaller XOR

[ARC129A] Smaller XOR

Score : 300300 points

Problem Statement

Given are integers NN, LL, and RR. Count the number of integers xx that satisfy both of the following conditions.

  • LxRL \leq x \leq R
  • (xN)<N(x \oplus N) < N (Here, \oplus denotes the bitwise XOR\mathrm{XOR}.)
What is the bitwise $\mathrm{XOR}$?

The bitwise $\mathrm{XOR}$ of integers $A$ and $B$, $A\oplus B$, is defined as follows:

  • When $A\oplus B$ is written in base two, the digit in the $2^k$'s place ($k \geq 0$) is $1$ if exactly one of $A$ and $B$ is $1$, and $0$ otherwise.
For example, we have 3\oplus 5 = 6 (in base two: 011\oplus 101 = 110).

Constraints

  • 1N10181 \leq N \leq 10^{18}
  • 1LR10181 \leq L \leq R \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN LL RR

Output

Print the answer.

2 1 2
1

For x=1x=1, LxRL \leq x \leq R is satisfied, but (xN)<N(x \oplus N) < N is not. For x=2x=2, both conditions are satisfied. There is no other xx that satisfies the conditions.

10 2 19
10
1000000000000000000 1 1000000000000000000
847078495393153025