A16397 | XOR-distance
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given integers $a$ , $b$ , $r$ . Find the smallest value of $|({a \oplus x}) - ({b \oplus x})|$ among all $0 \leq x \leq r$ .
$\oplus$ is the operation of [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), and $|y|$ is [absolute value](https://en.wikipedia.org/wiki/Absolute_value) of $y$ .
$\oplus$ is the operation of [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), and $|y|$ is [absolute value](https://en.wikipedia.org/wiki/Absolute_value) of $y$ .
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
Each test case contains integers $a$ , $b$ , $r$ ( $0 \le a, b, r \le 10^{18}$ ).
Each test case contains integers $a$ , $b$ , $r$ ( $0 \le a, b, r \le 10^{18}$ ).
输出格式
For each test case, output a single number — the smallest possible value.
输入输出样例
输入 #1
10 4 6 0 0 3 2 9 6 10 92 256 23 165 839 201 1 14 5 2 7 2 96549 34359 13851 853686404475946 283666553522252166 127929199446003072 735268590557942972 916721749674600979 895150420120690183
输出 #1
2 1 1 164 542 5 3 37102 27934920819538516 104449824168870225
In the first test, when $r = 0$ , then $x$ is definitely equal to $0$ , so the answer is $|{4 \oplus 0} - {6 \oplus 0}| = |4 - 6| = 2$ .
In the second test:
- When $x = 0$ , $|{0 \oplus 0} - {3 \oplus 0}| = |0 - 3| = 3$ .
- When $x = 1$ , $|{0 \oplus 1} - {3 \oplus 1}| = |1 - 2| = 1$ .
- When $x = 2$ , $|{0 \oplus 2} - {3 \oplus 2}| = |2 - 1| = 1$ .
Therefore, the answer is $1$ .
In the third test, the minimum is achieved when $x = 1$ .
In the second test:
- When $x = 0$ , $|{0 \oplus 0} - {3 \oplus 0}| = |0 - 3| = 3$ .
- When $x = 1$ , $|{0 \oplus 1} - {3 \oplus 1}| = |1 - 2| = 1$ .
- When $x = 2$ , $|{0 \oplus 2} - {3 \oplus 2}| = |2 - 1| = 1$ .
Therefore, the answer is $1$ .
In the third test, the minimum is achieved when $x = 1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted