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
41
42
43
44
45
#include <iostream>
#include <vector>

using namespace std;


long long getIlosc1(int number) {
	int couter = 0;
	
	int rem;

	while (number != 0) {
		rem = number % 2;
		if (rem == 1) couter++;
		number /= 2;
	}

	return couter;
}



int main()
{
	vector<int> vMain;
	int i = 1;
	while (vMain.size() < 1000000) {
		int ilosc = getIlosc1(i);
		for (int j = 0; j < ilosc; j++) vMain.push_back(i);
		i++;
	}

	int n;
	cin >> n;

	vector<int> out;
	while (n > 0) {
		out.push_back(vMain[n - 1]);
		n = n - getIlosc1(vMain[n - 1]);
	}
	
	
	cout << out.size()<< "\n";
	for (int i = 0; i < out.size(); i++) cout << out[i] << " ";
}