Submission details
Task:Sum of ones
Sender:aalto26em_002
Submission time:2026-09-28 17:15:20 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'long long int extended_gcd(long long int, long long int, long long int&, long long int&)':
input/code.cpp:57:6: error: 's' was not declared in this scope
   57 |     }s
      |      ^
input/code.cpp:59:35: error: 'x1' was not declared in this scope; did you mean 'x'?
   59 |     ll d = extended_gcd(b, a % b, x1, y1);
      |                                   ^~
      |                                   x
input/code.cpp:60:9: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
   60 |     x = y1;
      |         ^~
      |         |
      |         double (*)(double) noexcept
input/code.cpp:61:17: error: invalid operands of types 'double(double) noexcept' and 'long long int' to binary 'operator*'
   61 |     y = x1 - y1 * (a / b);
      |              ~~ ^ ~~~~~~~
      |              |       |
      |              |       long long int
      |              double(double) noexcept

Code

// #ifdef ONLINE_JUDGE
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #endif
#include "bits/stdc++.h"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i, a, b) for(__typeof(b) i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for(__typeof(a) i = a, _b = b; i >= _b; --i)
#define ALL(a) (a).begin(), (a).end()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define dq deque<int>
#define nend '\n'
using namespace std;
	
const ll inf = 1e18;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int MOD = 1e9 + 7; 
const ll hashi = 2e9 + 11;

inline ll add(ll a, ll b) { return (a + b) % MOD; }
inline ll sub(ll a, ll b) { return ((a - b) % MOD + MOD) % MOD; }
inline ll mul(ll a, ll b) { return (a * b) % MOD; }

inline ll binpow(ll a, ll b) {
    ll res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

inline ll modInverse(ll n) {
    return binpow(n, MOD - 2);
}

inline ll modDivide(ll a, ll b) {
    return (a % MOD * modInverse(b)) % MOD;
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1; y = 0;
        return a;
    }s
    ll x1, y1;
    ll d = extended_gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
void init_code() {
    fast;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
}
const int N=2e5+3;
ll n;
// bit b over 0..n repeats with period 2^(b+1): 2^b zeros then 2^b ones
void solve() {
    cin >> n;
    ll m=n+1, ans=0;
    FOR(b,0,50) {
        ll half=1LL<<b, cyc=half<<1;
        ans+=m/cyc*half+max(0LL,m%cyc-half);
    }
    cout << ans << nend;
}

int main() {
    init_code();

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    // #ifndef ONLINE_JUDGE
    // cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
    // #endif

    return 0;
}