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
#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[1000006], b[1000006], z[1000006];
bool f1[1000006], f2[1000006];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= 1000000; i *= 2)
	{
		f1[i] = 1;
	}
	for (int i = 1; i <= 1000000; ++i)
	{
		if (z[i - 1] >= n)
		{
			k = i - 1;
			m = z[i - 1];
			break;
		}
		if (f1[i])
		{
			a[i] = 1;
			z[i] = z[i - 1] + 1;
			k = i;
			continue;
		}
		a[i] = a[i - k] + 1;
		z[i] = a[i] + z[i - 1];
	}
	int k1 = k;
	for (int i = k; i > 0; --i)
	{
		if (m - a[i] >= n)
		{
			m -= a[i];
			--k1;
			f2[i] = 1;
		}
	}
	printf("%d\n", k1);
	for (int i = k; i > 0; --i)
	{
		if (!f2[i])
			printf("%d ", i);
	}
	return 0;
}