Advertisement
JouJoy

U

Dec 12th, 2021
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int a, b, n = 0;
  7.     cin >> a >> b;
  8.     while (a != b)
  9.     {
  10.         if (b > a)
  11.             if (b % 2 == 0)
  12.             {
  13.                 b /= 2;
  14.                 n++;
  15.             }
  16.             else
  17.             {
  18.                 b++;
  19.                 n++;
  20.             }
  21.  
  22.         else if (a > b)
  23.  
  24.         {
  25.             b++, n++;
  26.         }
  27.     }
  28.     cout << n << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement