#P9496. 「RiOI-2」hacker

    ID: 10020 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>洛谷原创O2优化位运算洛谷月赛

「RiOI-2」hacker

Background

Next to a small grove stands a fantasy castle. This is the land of Country E, and Little E is the king of Country E.

Now, the great king of Country E is putting on armor and going to war.

However, it is said that the king of Country E met two people called ACCEPT and BOTH. Who are they?

Problem Description

Given a positive integer nn, you can perform the following operations:

  • "ACCEPT". Pay a cost of 11 to bitwise OR the binary form of nn with a positive integer.
  • "BOTH". Pay a cost of 11 to bitwise AND the binary form of nn with a positive integer.

Both operations can be used multiple times (or not used at all). Please find the minimum cost to transform nn into mm.

Help: What are bitwise AND and bitwise OR

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, indicating the number of test cases.

The next TT lines each contain two positive integers n,mn, m, separated by spaces.

Output Format

Output TT lines. Each line contains one integer, which is the answer.

3
1 1
4 5
1 4
0
1
2

Hint

Sample Explanation

  • For n=1n = 1 and m=1m = 1, no operation is needed.
  • For n=4n = 4 and m=5m = 5, one feasible plan is to use "ACCEPT 11".
  • For n=1n = 1 and m=4m = 4, one feasible plan is to use "ACCEPT 998,244,853998{,}244{,}853" and then "BOTH 1414" in order.

Constraints

This problem uses bundled tests.

Subtask\text{Subtask} Points TT \leq n,mn, m \leq
00 3030 100100
11 7070 2×1052\times 10^5 101810^{18}

For all testdata, 1T2×1051 \le T \le 2 \times 10^5 and 1n,m10181 \le n, m \le 10^{18}.

Translated by ChatGPT 5