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

using namespace std;

int n, s, x = 0, a;
vector <int> w;

int main() {
    cin >> n;
    while (s < n) {
        x++;
        s += __popcount(x);
    }
    for (int i = x; i > 0; i--) {
        a = __popcount(i);
        if (s - a >= n) s -= a;
        else w.push_back(i);
    }
    cout << w.size() << endl;
    for (auto i : w) {
        cout << i << " ";
    }
}