1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>

using namespace std;

unsigned n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    unsigned sum = 0, k = 0;
    while (sum < n)
        sum += __builtin_popcount(++k);
    unsigned skip = sum - n;

    vector<int> res;    
    while (k > 0) {
        unsigned bits = __builtin_popcount(k);
        if (bits <= skip)
            skip -= bits;
        else res.push_back(k);
        --k;
    }
    cout << res.size() << '\n';
    for (int &i : res)
        cout << i << ' ';
    cout << '\n';
}