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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e6 + 5;

#define lowbit(x) ((x)&-(x))

int a[MAXN], sum[MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	
	for(int i=1; i<=n; ++i)
	{
		a[i] = a[i ^ lowbit(i)] + 1;
		sum[i] = sum[i-1] + a[i];
	}
	
	int pos = n;
	vector<int> ans;
	while(n)
	{
		while(sum[pos-1] >= n) --pos;
		ans.emplace_back(pos);
		n -= a[pos]; --pos;
	}
	
	printf("%d\n",(int)ans.size());
	for(int t: ans)
		printf("%d ",t);
	return 0;
}