1条回答 默认 最新
- Clarence Liu 2021-11-15 19:28关注
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; ll x, y; cin >> t; while(t--){ cin >> x >> y; if(x > y) swap(x, y); ll ans = 0; while((ll)(log2(x)) != (ll)(log2(y))){ y >>= 1; ans += 1; } while(x != y){ x >>= 1; y >>= 1; ans += 2; } cout << ans << '\n'; } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报