fork download
  1.  
  2. #include<bits/stdc++.h>
  3.  
  4.  
  5. using namespace std;
  6. using ll = long long;
  7.  
  8.  
  9. main(){
  10.  
  11.  
  12. ll n = 1e18;
  13. ll x = 1;
  14.  
  15. ll m = 0 , t = 0;
  16. ll a = 0 , b = 0;
  17.  
  18. for(ll i = 0 ; ; i ++){
  19. if((1ll << i) == n){
  20. m = t = i;
  21. break;
  22. }
  23. if((1ll << i) > n){
  24. m = i - 1;
  25. t = i;
  26. break;
  27. }
  28. }
  29.  
  30. a = (1ll << m);
  31. b = (1ll << t);
  32.  
  33.  
  34. ll ans = min(m + (n - a) , t + (b - n));
  35. printf("%lld\n" , ans);
  36.  
  37. return 0;
  38. }
  39.  
  40.  
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
152921504606847036