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
#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;

int dp[maxn];
vector <int> wyn;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; ++i) dp[i] = dp[i-1] + __builtin_popcount(i);
	
	int pop = n+1;
	while(n > 0)
	{
		int t = 0;
		int poc = 1, kon = pop-1;
		while(poc <= kon)
		{
			int sr = (poc+kon)>>1;
			if(dp[sr] >= n) t=sr, kon=sr-1;
			else poc=sr+1;
		}
		
		n -= __builtin_popcount(t);
		wyn.emplace_back(t);
		pop = t;
	}
	
	cout << wyn.size() << "\n";
	for(int i : wyn) cout << i << " ";
	
	return 0;
}