fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. using ll = long long;
  5. #define all(x) (x).begin(), (x).end()
  6. #define rall(x) (x).rbegin(), (x).rend()
  7. #define B(x) bitset<32>(x).to_ulong()
  8. #define Bll(x) bitset<64>(x).to_ullong()
  9. #define sz(x) (int)(x).size()
  10. #define pb(x) push_back(x)
  11. #define fi first
  12. #define sec second
  13. #define lb lower_bound
  14. #define up upper_bound
  15. #define endl '\n'
  16.  
  17. using namespace std;
  18. int main() {
  19. IOS;
  20. #ifndef ONLINE_JUDGE
  21. freopen("input.txt", "r", stdin);
  22. // freopen("output.txt", "w", stdout);
  23. #endif
  24. int n,m,ans=0;cin>>n>>m;
  25. if(m>n)
  26. while(m>n) {
  27. (m%2==0)?m>>=1:m++;
  28. ans++;
  29. }
  30. if(n>m) ans+=n-m;
  31. cout<<ans;
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5280KB
stdin
10 1
stdout
9