CF1918C XOR-distance
题目描述
给定整数 $a$、$b$、$r$。在所有满足 $0 \leq x \leq r$ 的 $x$ 中,求 $|({a \oplus x}) - ({b \oplus x})|$ 的最小值。
$\oplus$ 表示[按位异或](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)操作,$|y|$ 表示 $y$ 的[绝对值](https://en.wikipedia.org/wiki/Absolute_value)。
输入格式
第一行包含一个整数 $t$($1 \leq t \leq 10^4$),表示测试用例的数量。
每个测试用例包含三个整数 $a$、$b$、$r$($0 \leq a, b, r \leq 10^{18}$)。
输出格式
对于每个测试用例,输出一个数字,表示最小可能值。
说明/提示
在第一个测试中,当 $r = 0$ 时,$x$ 必定等于 $0$,所以答案为 $|4 \oplus 0 - 6 \oplus 0| = |4 - 6| = 2$。
在第二个测试中:
- 当 $x = 0$ 时,$|0 \oplus 0 - 3 \oplus 0| = |0 - 3| = 3$。
- 当 $x = 1$ 时,$|0 \oplus 1 - 3 \oplus 1| = |1 - 2| = 1$。
- 当 $x = 2$ 时,$|0 \oplus 2 - 3 \oplus 2| = |2 - 1| = 1$。
因此,答案为 $1$。
在第三个测试中,最小值在 $x = 1$ 时取得。
由 ChatGPT 4.1 翻译