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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	int t[n];
	bool stop = false;
	int ones = 0;
	// t[0] = 0;
	// t[1] = 1;
	// t[2] = 1;
	// t[3] = 2;
	// ones = 4;
	
	int tmp, numb = 0;
	
	int counter = 0, ones2;
	
	vector<int> resV;

	while (ones < n) {
		tmp = numb;
		resV.push_back(numb);
		ones2 = 0;
		while (tmp > 0) {
	        ones2 += tmp % 2;
	        tmp = tmp / 2;
	    }
	    t[numb] = ones2;
	    ones += ones2;
	    ++numb;
	}
	
	if (ones == n) {
		cout << resV.size() - 1 << endl;
		for (int i = resV.size() - 1; i > 0; i--) {
			cout << resV[i] << " ";
		}
	} else {
		cout << resV.size() - 2 << endl;
		int diff = ones - n;
		for (int i = resV.size() - 1; i > 0; i--) {
			if (t[i] == diff) {
				resV[i] = -1;
				break;
			}
			
		}
		for (int i = resV.size() - 1; i > 0; i--) {
			if (resV[i] > 0) {
				cout << resV[i] << " ";
			}
		}
	}
	// cout << endl;
	
	// int diff = 
	
	// for (int i = 0; i < numb; i++) {
	// 	cout << i << " = " << t[i] << endl;
	// }
	
	
	// cout << "ones = " << ones << endl;
	
	// for (int i = 0; i < resV.size(); i++) {
	// 	cout << resV[i] << " ";
	// }
	return 0;
}