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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+7;
int sum[N];
void solve(){
	int n;
	cin>>n;
	vector<int> ans;
	while(n){
		int l = 1,r = n;
		while(l!=r){
			int mid = (l+r)/2;
			if (sum[mid]<n){
				l = mid + 1;
			}
			else{
				r = mid;
			}
		}
		ans.push_back(l);
		n -= sum[l] - sum[l-1];
	}
	cout<<ans.size()<<endl;
	for(int to:ans){
		cout<<to<<' ';
	}
	cout<<endl;
}
signed main(){
	for(int i = 1;i<N;i+=1){
		sum[i] = sum[i-1] + __builtin_popcount(i);
	}
	int tt = 1;
	while(tt--){
		solve();
	}
}