CF1632C.Strange Test

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich.

Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers aa and bb (a<ba \lt b). After that, the student can apply any of the following operations any number of times:

  • a:=a+1a := a + 1 (increase aa by 11),
  • b:=b+1b := b + 1 (increase bb by 11),
  • a:=a ∣ ba := a \ | \ b (replace aa with the bitwise OR of aa and bb).

To get full marks on the test, the student has to tell the teacher the minimum required number of operations to make aa and bb equal.

Igor already knows which numbers the teacher will give him. Help him figure out what is the minimum number of operations needed to make aa equal to bb.

伊戈尔正在读11年级。明天他将参加学校最严格的老师——帕维尔·杰尼索维奇老师——所监考的信息学考试。

伊戈尔知道考试的流程:首先,老师会给每位学生两个正整数 aa 和 bb(满足 a<ba \lt b)。之后,学生可以任意次执行以下任意一种操作:

  • a:=a+1a := a + 1(将 aa 增加 11),
  • b:=b+1b := b + 1(将 bb 增加 11),
  • a:=a ∣ ba := a \ | \ b(将 aa 替换为 aa 与 bb 的按位或结果)。

为了在考试中获得满分,学生必须告诉老师:使 aa 与 bb 相等所需的最少操作次数。

伊戈尔已经知道了老师将给他的具体数值。请帮助他算出:使 aa 等于 bb 所需的最少操作次数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Description of the test cases follows.

The only line for each test case contains two integers aa and bb (1≤a<b≤1061 \le a \lt b \le 10^6).

It is guaranteed that the sum of bb over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅一行,包含两个整数 aa 和 bb(1≤a<b≤1061 \le a \lt b \le 10^6)。

保证所有测试用例的 bb 值之和不超过 10610^6。

输出格式

For each test case print one integer — the minimum required number of operations to make aa and bb equal.

对于每个测试用例,输出一个整数——使 aa 和 bb 相等所需的最少操作次数。

输入输出样例

  • 输入#1

    5
    1 3
    5 8
    2 5
    3 19
    56678 164422

    输出#1

    1
    3
    2
    1
    23329

说明/提示

In the first test case, it is optimal to apply the third operation.

In the second test case, it is optimal to apply the first operation three times.

In the third test case, it is optimal to apply the second operation and then the third operation.

在第一个测试用例中,最优策略是执行第三次操作。

在第二个测试用例中,最优策略是执行第一次操作三次。

在第三个测试用例中,最优策略是先执行第二次操作,再执行第三次操作。

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

首页