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

int32_t n;
int32_t m;
int32_t r;
int32_t k[130000];

int main() {
    std::ios_base::sync_with_stdio(false);

    std::cin >> n;

    k[0] = 0;

    m = 0;
    while (k[m] < n) {
        ++m;
        k[m] = k[m-1] + __builtin_popcount(static_cast<uint32_t>(m));
    }

    r = 0;
    for (int32_t i = m; i > 0; --i) {
        if (k[i] >= n && k[i-1] < n) {
            n -= __builtin_popcount(static_cast<uint32_t>(i));
            ++r;
        }
        else {
            k[i] = -1;
        }
    }

    std::cout << r << "\n";
    for (int32_t i = m; i > 0; --i) {
        if (k[i] > 0) {
            std::cout << i << " ";
        }
    }
    std::cout << "\n";
}