Codeforces Round 922 (Div. 2)
翻译中…
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, and $|y|$ is absolute value of $y$.
翻译中…
Input
翻译中…
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}$).
翻译中…
Output
翻译中…
For each test case, output a single number — the smallest possible value.
翻译中…
Note
翻译中…
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$.
翻译中…
样例
Input #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
Output #1
2
1
1
164
542
5
3
37102
27934920819538516
104449824168870225
InputCopy
OutputCopy
题目信息
标签
位运算
贪心
模拟
数学
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。