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
#include <cstdio>
#include <vector>

int main() {
    int n;
    scanf("%d", &n);
    int s = 0, curr = 0;
    while (s < n) {
        s += __builtin_popcount(++curr);
    }
    std::vector<int> res;
    while (curr > 0) {
        if (__builtin_popcount(curr) <= s - n) {
            s -= __builtin_popcount(curr);
        }
        else {
            res.push_back(curr);
        }
        curr--;
    }

    printf("%ld\n", res.size());
    for (unsigned i = 0; i < res.size(); ++i) {
        printf("%d ", res[i]);
    }
    printf("\n");
    return 0;
}