#3767. XOR Sequences
XOR Sequences
题目描述
You are given two distinct non-negative integers and . Consider two infinite sequences and , where
- ;
- .
Here, denotes the bitwise XOR operation of integers and .
For example, with , the first elements of sequence will look as follows: . Note that the indices of elements start with .
Your task is to find the length of the longest common subsegment of sequences and . In other words, find the maximum integer such that $ a_i = b_j, a_{i + 1} = b_{j + 1}, \ldots, a_{i + m - 1} = b_{j + m - 1} $ for some .
A subsegment of sequence is a sequence , where .
输入格式
Each test consists of multiple test cases. The first line contains a single integer ( ) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers and ( ) — the parameters of the sequences.
输出格式
For each test case, output a single integer — the length of the longest common subsegment.
输入输出样例 #1
输入 #1
4
0 1
12 4
57 37
316560849 14570961
输出 #1
1
8
4
33554432
说明/提示
In the first test case, the first elements of sequences and are as follows:
It can be shown that there isn't a positive integer such that the sequence occurs in as a subsegment. So the answer is .
In the third test case, the first elements of sequences and are as follows:
$ a = [56, 59, 58, 61, 60, 63, 62, 49, 48, 51, 50, 53, 52, 55, 54, \textbf{41, 40, 43, 42}, 45, \ldots] $
$ b = [36, 39, 38, 33, 32, 35, 34, 45, 44, 47, 46, \textbf{41, 40, 43, 42}, 53, 52, 55, 54, 49, \ldots] $
It can be shown that one of the longest common subsegments is the subsegment with a length of .