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
#include<bits/stdc++.h>
using namespace std;
int tab[1000000]={0,1}, wyn[1000000];
int main()
{
	int n, i = 1, j;
	cin >> n;
	while(tab[i] < n){
		i++;
		tab[i] = tab[i-1] + __builtin_popcount(i);
	}
	if(n == tab[i]) {
		cout << i << endl;
		while(i--) cout << i + 1
		<<" ";
		return 0;
	}
	do{
		wyn[j] = i;
		j++;
		n = n - __builtin_popcount(i);
		while(tab[i] >= n) i--;
		i++;
	} while(n > 0);
	cout << j << endl;
	for(i = 0; i < j; i++) cout << wyn[i] <<" ";
return 0;
}