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

constexpr int MAX_N = 1e6 + 1;

int n,number_of_bits,iter,pocz,kon,mid,prefix[MAX_N];
vector <int> v;
int main()
{
	scanf("%d",&n);
	for(int i = 1;i<=n;++i)
	{
		prefix[i] = prefix[i - 1] + __builtin_popcount(i);
	}
	iter = n;
	while(n)
	{
		while(prefix[iter] >= n)--iter;
		++iter;
		v.push_back(iter);
		n -= __builtin_popcount(iter);
	}
		
	
	printf("%d\n",v.size());
	for(int i = 0;i < v.size();++i)printf("%d ",v[i]);
}