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

constexpr int N = 1e6 + 1;
int full[2*N];

int main() {
    int n; scanf("%d", &n);

    long sum = 0;
    for (int i = 1; i <= 2 * n; i++) {
        sum += __builtin_popcount(i);
        if (sum > 2 * n) break;
        full[sum] = i;
    }
    std::vector<int> result;
    while (n > 0) {
        int i = n;
        while (full[i] == 0) {
            i++;
        }
        result.push_back(full[i]);
        n -= __builtin_popcount(full[i]);
    }
    printf("%lu\n", result.size());
    for (int x : result) {
        printf("%d ", x);
    }
}