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 <algorithm>
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

long a[1000001];

int main()
{
	long n, l=0;
	scanf("%ld", &n);
	long d = 1;
	long i = 0;
	while (l < n)
	{
		if (++i >= 2*d)
			d *= 2;
		a[i] = 1 + a[i - d];
		l += a[i];
	}

    long r = 0, l2 = l, n2 = n, i2 = i;
	while (n2 > 0)
	{
		if (l2 - a[i2] < n2)
		{
			++r;
			n2 -= a[i2];
		}
		l2 -= a[i2];
		--i2;
	}
	printf("%ld\n", r);
	while (n > 0)
	{
		if (l - a[i] < n)
		{
			printf("%ld ", i);
			n -= a[i];
		}
		l -= a[i];
		--i;
	}
	return 0;
}