Advertisement
Josif_tepe

Untitled

Mar 18th, 2022
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.     ll N, S;
  11.     cin >> S >> N;
  12.     ll cnt = 0;
  13.     while(N >= 2 * S) {
  14.         if(N == S + 2) {
  15.             N = S;
  16.         }
  17.        else if(N % 2 == 1) {
  18.             N--;
  19.         }
  20.         else {
  21.             N /= 2;
  22.         }
  23.         cnt++;
  24.     }
  25.     cout << cnt + (N - S + 1) / 2 << endl;
  26.     return 0;
  27. }
  28.  
  29. // 99123959998
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement