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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>

using namespace std;

typedef long long lld;

constexpr int INF = (1<<30) - 1;
constexpr lld LINF = (1LL << 62) - 1;
constexpr int MAX_N = 1000000;
vector<int> result;

void solve(int test_number)
{
	result.clear();
	int n;
	scanf("%d", &n);
	int i = 1;
	int bit_sum = 0;
	while(bit_sum < n)
	{
		bit_sum += __builtin_popcount(i);
		++i;
	}
	i--;
	while (i)
	{
		int bits = __builtin_popcount(i);
		if (bit_sum - bits < n)
		{
			result.push_back(i);
			bit_sum -= bits;
			n -= bits;
		}
		else
		{
			bit_sum -= bits;
		}
		i--;
	}
	printf("%u\n", result.size());
	for (size_t i = 0; i < result.size(); ++i)
	{
		printf("%d ", result[i]);
	}
}

int main()
{
	int test_number = 1;
	// scanf("%d", &test_number);
	for (int test_id = 0; test_id < test_number; ++test_id)
	{
		solve(test_number);
	}
}