#P9496. 「RiOI-2」hacker
「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 , you can perform the following operations:
- "ACCEPT". Pay a cost of to bitwise OR the binary form of with a positive integer.
- "BOTH". Pay a cost of to bitwise AND the binary form of with a positive integer.
Both operations can be used multiple times (or not used at all). Please find the minimum cost to transform into .
Help: What are bitwise AND and bitwise OR
Input Format
This problem has multiple test cases.
The first line contains a positive integer , indicating the number of test cases.
The next lines each contain two positive integers , separated by spaces.
Output Format
Output lines. Each line contains one integer, which is the answer.
3
1 1
4 5
1 4
0
1
2
Hint
Sample Explanation
- For and , no operation is needed.
- For and , one feasible plan is to use "ACCEPT ".
- For and , one feasible plan is to use "ACCEPT " and then "BOTH " in order.
Constraints
This problem uses bundled tests.
| Points | |||
|---|---|---|---|
For all testdata, and .
Translated by ChatGPT 5