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
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> odp;
    vector<int> sum(1000001);
    sum[0] = 0;
    for (int i = 1; i < 1000001; ++i)
        sum[i] = sum[i - 1] + __builtin_popcount(i);
    int akt = 1000000;
    while (n > 0)
    {
        while (akt >= 1 && sum[akt - 1] >= n - __builtin_popcount(akt))
            --akt;
        ++akt;
        odp.push_back(akt);
        n -= __builtin_popcount(akt);
        --akt;
    }
    cout << odp.size() << endl;
    for (int i = 0; i < odp.size(); ++i)
        cout << odp[i] << " ";
    return 0;
}