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;

int n;
int num[10000001];

int main()
{
    scanf("%d", &n);
    int it = 1;
    for(int i=1; it <= n; ++i)
    {
        int b = __builtin_popcount(i);
        for(int j=it; j<it+b; j++)
        {
            num[j] = i;
        }
        it += b;
    }
    vector<int> odp;
    while(n)
    {
        odp.push_back(num[n]);
        n -= __builtin_popcount(num[n]);
    }
    printf("%ld\n", odp.size());
    for(auto e:odp)
        printf("%d ", e);
    printf("\n");
}