Iamtui1010

dembit1.cpp

Mar 8th, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3.  
  4. #define long long long
  5. #define nln '\n'
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     cin.tie(0)->sync_with_stdio(0);
  12.     cout.tie(0)->sync_with_stdio(0);
  13.     //freopen("dembit1.inp", "r", stdin);
  14.     long n;
  15.     cin >> n;
  16.     long ans = 0, add = 0;
  17.     while (n > 0){
  18.         long i = 0, b = 1;
  19.         do{
  20.             n -= b;
  21.             ans += b + b/2*i+add*b;
  22.             ++i;
  23.             b *= 2;
  24.         }   while (b <= n);
  25.         ++add;
  26.         if (n > 0)
  27.             ans += add;
  28.         n--;
  29.     }
  30.     cout << ans << nln;
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment