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
#include <stdio.h>
#include <vector>
#include <algorithm>
std::vector<int> res;
int main()
{

    constexpr int total= 150000;
    int tab[total]={};
    for(int i =1;i<total;i++)
    {
        int x = i;
        tab[i] = tab[i-1];
        do  
        {   
            tab[i] += x%2;
        }while(x/=2);
    }
    int n;
    scanf("%d",&n);
    while(n>0)
    {
        int index = std::lower_bound(tab, tab+total,n) - tab;
        res.push_back(index);
        n-= tab[index] - tab[index-1];
    }
    
    printf("%d\n", res.size());
    for(const auto &x: res)
        printf("%d ",x);
    printf("\n");
    return 0;
}