1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <cstdio>

#define scanf(...) scanf(__VA_ARGS__)?:0

int n, i, j, s[121000], x[121000];

int main() {
	scanf("%d", &n);
	for (i = 1; s[i-1] < n; i++) s[i] = s[i-1] + __builtin_popcount(i);
	i--;
	while (n > 0) {
		x[j++] = i;
		n -= __builtin_popcount(i);
		while (s[i-1] >= n) i--;
	}
	printf("%d\n", j);
	for (int i = 0; i < j; i++) printf("%d ", x[i]);
	printf("\n");
}