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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <cstdio>
#include <cstdlib>
#include <cstring>

static unsigned moc(unsigned x)
{
	unsigned r = 0;

	while (x) {
		r += x & 1;
		x >>= 1;
	}

	return r;
}

int main(void)
{
	unsigned n, max = 0, sum = 0, diff, i;

	scanf("%u", &n);

	while (sum < n) {
		max++;
		sum += moc(max);
	}

	diff = sum - n;
	printf("%u\n", max - !!diff);
	for (i = max; i > 0; i--) {
		if (diff && moc(i) == diff) {
			diff = 0;
			continue;
		}
		if (i != max)
			putchar(' ');
		printf("%u", i);
	}
	putchar('\n');

	return 0;
}