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

typedef unsigned int uint;


uint get_ones_count(int number) {
    int ones_count = 0;

    while (number != 0) {
        if (number % 2 != 0) {
            ones_count++;
        }

        number /= 2;
    }

    return ones_count;
}


int main() {
    uint notes_power;
    std::cin >> notes_power;

    std::vector<uint> notes;
    int number;

    uint power_sum = 0;
    for (number = 1; power_sum < notes_power; ++number) {
        power_sum += get_ones_count(number);
    }

    while (notes_power > 0) {
        while (power_sum >= notes_power) {
            number--;
            power_sum -= get_ones_count(number);
        }

        notes.push_back(number);
        notes_power -= get_ones_count(number);
    }

    std::cout << notes.size() << '\n';
    for (auto& item : notes) std::cout << item << ' ';
    return 0;
}