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

using namespace std;

const int N = 1e6 + 50;

int f[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	for (int i = 1; i <= 1e6; ++i) {
		f[i] = f[i - 1] + __builtin_popcount(i);
	}
	vector<int> ret;
	int su = 0;
	for (int i = 1e6; i >= 1; --i) {
		if (su + f[i - 1] < n) {
			su += __builtin_popcount(i);
			ret.push_back(i);
		}
	}
	cout << ret.size() << '\n';
	for (int x : ret)
		cout << x << ' ';
}