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

int n,a[N];

signed main() {
	ios::sync_with_stdio(false),cin.tie(0);
	cout.precision(10),cout.setf(ios::fixed);
	
	cin>>n;
	int sum=0,m=0;
	for (int i=1;sum<n;i++) {
		sum+=a[i]=__builtin_popcount(i);
		m=i;
	}
	int k=sum-n;
	vector<int>ans;
	for (int i=m;i>=1;i--) {
		if (a[i]<=k) {
			k-=a[i];
		} else {
			ans.emplace_back(i);
		}
	}
	cout<<ans.size()<<"\n";
	for (int i:ans) {
		cout<<i<<" ";
	}
	
	return 0;
}