欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1979B.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 .
Input
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.
Output
For each test case, output a single integer — the length of the longest common subsegment.
Note
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 .
Samples
4
0 1
12 4
57 37
316560849 14570961
1
8
4
33554432
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |