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
#include <bits/stdc++.h>

int main() {
	std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
	int n;
	std::cin >> n;

	int cnt = 0;
	std::vector<int> v;
	int i = 1;
	while (1) {
		v.push_back(i);
		cnt += __builtin_popcount(i);
		if (cnt >= n) break;
		i++;
	}

	cnt -= n;
	int k = v.size();
	for (int i = v.size()-1; i >= 0; i--)
		if (__builtin_popcount(v[i]) <= cnt) {
			cnt -= __builtin_popcount(v[i]);
			v[i] = -1;
			k--;
		}
	std::cout << k << "\n";
	for (int i = v.size()-1; i >= 0; i--)
		if (v[i] != -1)
			std::cout << v[i] << " ";
	std::cout << "\n";
}