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
#include <bits/stdc++.h>
using namespace std;
#pragma GCC maksuje_zadania_na_essie("pot200");

using ui = unsigned;

int main() {

    cin.tie(0)->sync_with_stdio(false);
    ui n; cin >> n;

	ui sum = 0;
	vector<ui> s;

	ui val = 0;

	while(sum < n) {
		val++;
		sum += __builtin_popcount(val);
		s.push_back(val);
	}

	ui bits_to_remove = (sum - n);

	cout << s.size() - (bits_to_remove > 0) << '\n';

	for(ui i = s.size(); i != -1; i--) {
		if(__builtin_popcount(i) == bits_to_remove) {
			bits_to_remove = 0;
		}
		else {
			cout << i << ' ';
		}
	}

}