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
#include <stdio.h>

int popcount(int x)
{
	return __builtin_popcount(x); // gcc specific
}

int output[1000000];
int output_len = 0;

int main(void)
{
	int n;
	int sum = 0;
	int i = 0;

	scanf("%d", &n);

	while (sum < n) {
		i++;
		sum += popcount(i);
	}

	while (i > 0) {
		if (sum - popcount(i) < n)
			output[output_len++] = i;
		else
			sum -= popcount(i);
		i--;
	}

	printf("%d\n", output_len);
	for (i = 0; i < output_len; i++)
		printf("%d ", output[i]);
	printf("\n");

	return 0;
}