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
#include <bits/stdc++.h>

using namespace std;
int n,i;
int ile;
int l[10005];
int last;
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=1;ile<n;i++)
    {
        ile+=__builtin_popcount(i);
        l[__builtin_popcount(i)]=i;
    }
    i--;
    last=l[ile-n];
    if(last!=0)cout<<i-1<<endl;
    else cout<<i<<endl;
    for(int j=i;j>0;j--)
    {
        if(j!=last)cout<<j<<" ";
    }
    return 0;
}