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
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;

int bits(int n)
{
    int ret = 0;
    while (n)
    {
        n = n & (n - 1);
        ret++;
    }
    return ret;
}

int tab[1000001];
vector<int> v;
int main() {
    int n;
    cin >> n;
    tab[0] = 0;
    int ind=1;
    while(true) {
        tab[ind] = tab[ind-1] + bits(ind);
        if(tab[ind] >= n) {
            break;
        }
        ind++;
    }
    v.push_back(ind);
    n -= bits(ind);
    while(n > 0) {
        while(tab[ind-1] >= n) {
            ind--;
        }
        v.push_back(ind);
        n -= bits(ind);
    }
    cout << v.size() << "\n";
    for(int i=0;i<v.size();i++) {
        cout << v[i] << " ";
    }
    return 0;
}