Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("dembit1.inp", "r", stdin);
- long n;
- cin >> n;
- long ans = 0, add = 0;
- while (n > 0){
- long i = 0, b = 1;
- do{
- n -= b;
- ans += b + b/2*i+add*b;
- ++i;
- b *= 2;
- } while (b <= n);
- ++add;
- if (n > 0)
- ans += add;
- n--;
- }
- cout << ans << nln;
- return 0;
- }
Add Comment
Please, Sign In to add comment