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 <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int tab[1000002];
vector<int> V;
int main()
{
	int n;
    cin>>n;
    for (int i=1; i<=1000000; i++)
      tab[i]=tab[i-1]+__builtin_popcount(i);
     
    for (int i=1000000; i>0; i--)
    {
       if (tab[i]>=n && tab[i-1]<n)
       { 
          V.push_back(i);
          n-=__builtin_popcount(i);
       }
    }
    cout<<V.size()<<endl;
    for(int i=0; i<V.size(); i++)
         cout<<V[i]<<" ";
	return 0;
}