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

constexpr int MAXN = 1'000'001;

int sum_bits[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	for (int i = 1; i < MAXN; i++) {
		sum_bits[i] = sum_bits[i - 1] + __builtin_popcount(i);
	}
	
	int n;
	cin >> n;
	
	vector<int> result;
	for (int i = MAXN - 1; i >= 1; i--) {
		if (sum_bits[i] >= n && sum_bits[i - 1] < n) {
			result.emplace_back(i);
			n -= __builtin_popcount(i);
		}
	}
	
	cout << result.size() << '\n';
	for (int i = 0; i < (int) result.size(); i++) {
		cout << result[i] << (i == (int) result.size() - 1 ? '\n' : ' ');
	}
	
	return 0;
}