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
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>

using namespace std;

#define count_ones(x) __builtin_popcount(x)

constexpr int preprocesing_size = 121000;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    vector<int> bit_count(preprocesing_size);
    for (int i = 0; i < (int)bit_count.size(); i++)
        bit_count[i] = count_ones(i);

    vector<int> bit_count_sum(bit_count.size());
    for (int i = 1; i < (int)bit_count_sum.size(); i++)
        bit_count_sum[i] = bit_count_sum[i-1] + bit_count[i];

    //cout << count_ones(7) << "\n";

    //for (int i = 100000; i < 200001; i += 1000)
    //    cout << i << " -> " <<  bit_count_sum[i] << "\n";

    //for (int i = 0; i < 10; i++)
    //    cout << i << " -> " << bit_count[i] << "\n";

    int n; cin >> n;
    int i = 0;
    while (bit_count_sum[i] < n) i++;

    int sum = bit_count_sum[i];
    vector<int> result = {i};
    while (i > 0)
    {
        i--;
        if (sum - bit_count[i] >= n)
            sum -= bit_count[i];
        else
            result.push_back(i);
    }

    cout << result.size() << "\n";
    for (const auto& e : result)
        cout << e << " ";
    cout << "\n";
}