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;
int pref[1000005];
vector<int> odp;

int main() {
	scanf("%d", &n);
	pref[0] = 0;
	int it = 0;
	for(int i = 1; pref[i-1] < n; ++i) {
		pref[i] = pref[i-1] + __builtin_popcount(i);
		it = i;
	}
	for(int i = it; n > 0; --i) {
		if(pref[i] >= n && pref[i-1] < n) {
			n -= __builtin_popcount(i);
			odp.push_back(i);
		}
	}
	printf("%d\n", odp.size());
	for(auto i : odp) printf("%d ", i);
	printf("\n");
}