fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16.  
  17. // Loops
  18. #define rep(i,a,b) for(int i=a;i<b;++i)
  19. #define each(x, a) for (auto &x : a)
  20.  
  21. // Logic
  22. void solve() {
  23. int a, b;
  24. cin >> a >> b;
  25.  
  26. int a1 = a, b1 = b;
  27. int A = 0, B = 0;
  28. while ((a1 % 2) == 0) { a1 /= 2; ++A; }
  29. while ((b1 % 2) == 0) { b1 /= 2; ++B; }
  30.  
  31. if (a1!= b1) {
  32. cout << -1 << '\n';
  33.  
  34. return;
  35. }
  36.  
  37. int d = B - A;
  38. int absd = d >= 0 ? d : -d;
  39. int ans = absd / 3 + (absd % 3 ? 1 : 0);
  40. cout << ans << '\n';
  41. }
  42.  
  43. // Main
  44. int32_t main() {
  45. fast_io;
  46. int t;
  47. cin>>t;
  48. while (t--) solve();
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5308KB
stdin
10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8
stdout
1
1
-1
0
2
2
14
0
-1
-1