Advertisement
sazid_iiuc

Untitled

Jun 5th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int testcase;
  7.  
  8.     cin >> testcase;
  9.  
  10.     while (testcase--)
  11.     {
  12.         long long int a, b, temp, count = 0;
  13.         bool flag = false;
  14.  
  15.         cin >> a >> b;
  16.  
  17.         if (a == b)
  18.         {
  19.             cout << 0;
  20.         }
  21.         else if (a > b)
  22.         {
  23.             if (a % b == 0)
  24.             {
  25.                 temp = a / b;
  26.  
  27.                 while (temp != 0)
  28.                 {
  29.  
  30.                     if (temp % 2 == 0)
  31.                     {
  32.                         temp = temp / 2;
  33.                         count++;
  34.                     }
  35.  
  36.                     else if (temp == 1)
  37.                     {
  38.                         //count++;
  39.                         break;
  40.                     }
  41.                     else
  42.                     {
  43.                         cout << -1;
  44.                         flag = true;
  45.                         break;
  46.                     }
  47.                 }
  48.  
  49.                 int temp1 = count % 3;
  50.                 int temp2 = temp1 % 2;
  51.                 int result = count / 3 + temp1 / 2 + temp2;
  52.                 if(flag == false)
  53.                 {
  54.                     cout << result;
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 cout << -1;
  60.             }
  61.         }
  62.         else if (a < b)
  63.         {
  64.             if (b % a == 0)
  65.             {
  66.                 temp = b / a;
  67.  
  68.                 while (temp != 0)
  69.                 {
  70.  
  71.                     if (temp % 2 == 0)
  72.                     {
  73.                         temp = temp / 2;
  74.                         count++;
  75.                     }
  76.  
  77.                     else if (temp == 1)
  78.                     {
  79.                         //count++;
  80.                         break;
  81.                     }
  82.                     else
  83.                     {
  84.                         cout << -1;
  85.                         flag = true;
  86.                         break;
  87.                     }
  88.                 }
  89.  
  90.                 int temp1 = count % 3;
  91.                 int temp2 = temp1 % 2;
  92.                 int result = count / 3 + temp1 / 2 + temp2;
  93.                 if (flag == false)
  94.                     cout << result;
  95.             }
  96.             else
  97.             {
  98.                 cout << -1;
  99.             }
  100.         }
  101.         cout << endl;
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement