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;


int32_t a, last = 1;
vector<int32_t> seq;


int main()
{
    scanf("%" SCNd32, &a);

    int32_t sum = 1;
    while (sum < a) {
        ++last;
        sum += __builtin_popcount(last);
    }

    for (; last != 0; --last) {
        if (sum - __builtin_popcount(last) < a) {
            seq.emplace_back(last);
            a -= __builtin_popcount(last);
        }
        sum -= __builtin_popcount(last);
    }

    printf("%zu\n", seq.size());
    for (int32_t i = 0; i < seq.size(); ++i) printf(i == 0 ? "%" PRId32 : " %" PRId32, seq[i]);
    printf("\n");
}