1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;

const int N = 1010101;
int n, a[N], ans[N];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i < N; i++) {
        a[i] = a[i - 1] + __builtin_popcount(i);
    }
    int sz = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (a[i] < n) {
            n -= __builtin_popcount(i + 1);
            ans[sz++] = i + 1;
        }
    }
    cout << sz << '\n';
    for (int i = 0; i < sz; i++) {
        cout << ans[i] << ' ';
    }
}