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
31
32
33
34
35
#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector <int> res;
    int pref_sum = 0;
    int k = 0;
    while(pref_sum < N) {
        k++;
        pref_sum += __builtin_popcount(k);
    }
    res.push_back(k);
    int a = __builtin_popcount(k);
    pref_sum -= a;
    N -= a;
    k--;
    while(N > 0) {
        int bits = __builtin_popcount(k);
        if (pref_sum - bits < N) {
            res.push_back(k);
            N -= bits;
        }
        pref_sum -= bits;
        k --;
    }
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}