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
// Kacper Orszulak
#include <cstdio>
#include <vector>
using namespace std;

int main(void) {
	int wanted_sum;
	scanf("%d", &wanted_sum);

	int sum = 0;
	int n = 0;
	for (; sum < wanted_sum; sum += __builtin_popcount(++n)) { }

	vector<int> arr;
	for (; n >= 1; --n) {
		const int new_sum = sum - __builtin_popcount(n);
		if (new_sum >= wanted_sum)
			sum = new_sum;
		else
			arr.push_back(n);
	}

	printf("%zu\n", arr.size());
	for (const int e : arr)
		printf("%d ", e);
	printf("\n");

	return 0;
}