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
44
45
46
47
#include<bits/stdc++.h>
using namespace std;

int n;
vector<int> wyn;
int count_bits(int x)
{
    int z=1;
    int wyn=0;
    while(z<=x)
    {
        if( (z&x) )
        {
            wyn++;
        }
        z*=2;
    }
    return wyn;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    int sum=0;
    int i=0;
    while(sum<n)
        sum+=count_bits(++i);
    while(n)
    {
        if(sum-count_bits(i)<n)
        {
            n-=count_bits(i);
            wyn.push_back(i);
        }
        sum-=count_bits(i);
        i--;
    }
    cout << wyn.size() << "\n";
    for(auto x:wyn)
        cout << x << " ";

    return 0;
}