Codeforces Global Round 31 (Div. 1 + Div. 2)
E
No Effect XOR
Codeforces
2300
原题
← DF1 →
翻译中…

In the jungle, there is a lake with infinite lily pads on it. The lily pads are numbered with non-negative integers $0, 1, 2, 3, \ldots$. The lily pads with numbers between $l$ and $r$ inclusive are called suitable, while all other lily pads are not suitable for the frogs to sit on.

翻译中…

Currently, a single frog is sitting on each suitable lily pad.

翻译中…

Ostad is watching the lake and wants to reorder the frogs. To do so, Ostad can pick a positive integer $x$ and announce it to the frogs. After hearing the number, the frog sitting on the $i$-th lily pad will jump to the $(i \oplus x)$-th one, where $\oplus$ denotes the bitwise XOR operation.

翻译中…

Ostad likes the frogs, and therefore he wants to pick the number $x$ in such a way that all frogs stay within the range of suitable lily pads.

翻译中…

Help Ostad by counting how many different numbers $x$ Ostad can choose such that no frog jumps outside the suitable segment of the lily pads.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.

翻译中…

For each test case, there is a single line containing two integers $l$ and $r$ ($1 \leq l \leq r \leq 10^{15}$).

翻译中…

Output

翻译中…

For each test case, output a single integer denoting the number of valid values for $x$.

翻译中…

Note

翻译中…

In the first test case, $x = 3$ is the only number that Ostad can choose, as $1 \oplus 3 = 2$ and $2 \oplus 3 = 1$, which are within the range $[1, 2]$.

翻译中…

There are no valid choices for Ostad in the second and third test cases. For the second case, since we require $x \gt 0$, the only frog that we have will leave the range. Similarly, in the third case, no valid $x$ exists to keep the frogs within the desired range.

翻译中…

In the fourth test case, Ostad can choose $1$, $2$, or $3$.

翻译中…

样例

Input #1
5
1 2
3 3
2 4
4 7
24189255811072 59373627899903
Output #1
1
0
0
3
2199023255551
InputCopy OutputCopy
题目信息
题号
2180E
时间限制
2 s
内存限制
256 MB
标签
位运算
分治
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。