#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        long long n, m;
        cin >> n >> m;
        if (n == m) {
            cout << 0 << endl;
        } else if (n < m) {
            int ans = 0;
            while (n < m) {
                if ((n | (n + 1)) <= m) {
                    n = n | (n + 1);
                    ans++;
                } else {
                    n++;
                    ans++;
                }
            }
            cout << ans << endl;
        } else {
            int ans = 0;
            while (n > m) {
                if ((n & (n - 1)) >= m) {
                    n = n & (n - 1);
                    ans++;
                } else {
                    n--;
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}
``
# 86 T1## 题目描述现在有正整数 $n$有以下操作;- 「ACCEPT」。花费 $1$ 的代价将 $n$ 二进制httpsoi-wikiorgmathbase#E4BA8CE8BF9BE588B6按位或上 一个正整数。- 「BOTH」。花费 $1$ 的代价将 $n$ 二进制httpsoi-wikiorgmathbase#E4BA8CE8BF9BE588B6按位与上 一个正整数。两种操作均可

原文地址: http://www.cveoy.top/t/topic/iIRJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录