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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int count_bit(int x){
	int res = 0;
	while(x){
		res+= x&1;
		x >>= 1;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int x = 0, it=1;
	vector<int> v, v2;
	while(x < n){
		v.push_back(it);
		x += count_bit(it);
		it++;
	}
	for(int i=v.size()-1; i>=0; i--){
		if(x - count_bit(v[i]) >= n){
			x -= count_bit(v[i]);
			continue;
		}
		v2.push_back(v[i]);
	}
	cout<<v2.size()<<"\n";
	for(auto i : v2){
		cout<<i<<" ";
	}
	cout<<"\n";
	return 0;
}