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
36
37
38
#include <cstdio>
#include <vector>
using namespace std;

const int maxN = 121000;
int bestres[maxN];
int M = 0;

int find_smallest(int x) {
    int a = 0, b = M + 1;
    while (b - a > 1) {
        int avg = (a + b) / 2;
        if (bestres[avg] < x)
            a = avg;
        else
            b = avg;
    }
    return b;
}

int main() {
    int N;
    scanf("%d", &N);
    while (bestres[M] <= N) {
        M++;
        bestres[M] = bestres[M - 1] + __builtin_popcount(M);
    }
    vector<int> res;
    while (N) {
        res.push_back(find_smallest(N));
        N -= __builtin_popcount(res.back());
    }
    printf("%lu\n", res.size());
    for (int a : res)
        printf("%d ", a);
    puts("");
    return 0;
}