CF1918C.XOR-distance

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given integers aa, bb, rr. Find the smallest value of ∣(a⊕x)−(b⊕x)∣|({a \oplus x}) - ({b \oplus x})| among all 0≤x≤r0 \leq x \leq r.

⊕\oplus is the operation of bitwise XOR, and ∣y∣|y| is absolute value of yy.

给定整数 aa、bb、rr。求所有满足 0≤x≤r0 \leq x \leq r 的整数 xx 中,∣(a⊕x)−(b⊕x)∣|({a \oplus x}) - ({b \oplus x})| 的最小值。

⊕\oplus 表示按位异或运算,∣y∣|y| 表示 yy 的绝对值。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case contains integers aa, bb, rr (0≤a,b,r≤10180 \le a, b, r \le 10^{18}).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例包含整数 aa、bb、rr(0≤a,b,r≤10180 \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=0r = 0, then xx is definitely equal to 00, so the answer is ∣4⊕0−6⊕0∣=∣4−6∣=2|{4 \oplus 0} - {6 \oplus 0}| = |4 - 6| = 2.

In the second test:

  • When x=0x = 0, ∣0⊕0−3⊕0∣=∣0−3∣=3|{0 \oplus 0} - {3 \oplus 0}| = |0 - 3| = 3.
  • When x=1x = 1, ∣0⊕1−3⊕1∣=∣1−2∣=1|{0 \oplus 1} - {3 \oplus 1}| = |1 - 2| = 1.
  • When x=2x = 2, ∣0⊕2−3⊕2∣=∣2−1∣=1|{0 \oplus 2} - {3 \oplus 2}| = |2 - 1| = 1.

Therefore, the answer is 11.

In the third test, the minimum is achieved when x=1x = 1.

在第一个测试中,当 r=0r = 0 时,xx 必然等于 00,因此答案为 ∣4⊕0−6⊕0∣=∣4−6∣=2|{4 \oplus 0} - {6 \oplus 0}| = |4 - 6| = 2。

在第二个测试中:

  • 当 x=0x = 0 时,∣0⊕0−3⊕0∣=∣0−3∣=3|{0 \oplus 0} - {3 \oplus 0}| = |0 - 3| = 3;
  • 当 x=1x = 1 时,∣0⊕1−3⊕1∣=∣1−2∣=1|{0 \oplus 1} - {3 \oplus 1}| = |1 - 2| = 1;
  • 当 x=2x = 2 时,∣0⊕2−3⊕2∣=∣2−1∣=1|{0 \oplus 2} - {3 \oplus 2}| = |2 - 1| = 1。

因此,答案为 11。

在第三个测试中,最小值在 x=1x = 1 时取得。

输入解题思路,AI测评打分。不知道怎么写?

首页