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;

const int MAX=1e6+5;

int last[21];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, sum=0, it=1;
    cin >>n;
    while(sum<n)
    {
        int temp=__builtin_popcount(it);
        sum+=temp;
        last[temp]=it;
        it++;
    }
    it--;
    if(sum-n==0) cout <<it <<"\n";
    else cout <<it-1 <<"\n";
    while(it>0)
    {
        if(it!=last[sum-n]) cout <<it <<" ";
        it--;
    }
}