intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); ull x, ans = 0; cin >> x; int n; for (n = 1; S(n-1) <= x; ++n) {} --n; ans += D(n-1);
ull y = x - S(n-1); ull d = y/n + (y%n!=0); bitset<64> b((1ull<<(n-1))+d-1); int prefsum = 1; for (int i = n-2; i >= 0; --i) { if (b[i] == 1) { ans += (prefsum)*(1ull<<i) + D(i); prefsum++; } } for (int i = 0; i < y-n*(d-1); i++) { ans += b[n-1-i]; }