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
40
//Dawid Lebryk
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;
const int MAXN = 1e6;

vector<int> popcnt, pref, W;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	pref.push_back(1);
	popcnt.push_back(1);
	int l = 1;
	while (pref[l - 1] <= MAXN)
	{
		popcnt.push_back(__builtin_popcount(l + 1));
		pref.push_back(popcnt[l] + pref[l - 1]);
		++l;
	}
	for (int i = pref.size() - 1; i >= 0; --i)
	{
		if (pref[i] < n)
		{
			W.push_back(i + 2);
			n -= popcnt[i + 1];
		}
	}
	if (n == 1) W.push_back(1);
	cout << W.size() << "\n";
	for (int i = 0; i < W.size(); i++)
	{
		cout << W[i] << " ";
	}
}