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
#include <cstdio>
#include <vector>
using namespace std;

int beatpower(int note) {
    int power = 0;
    while(note) {
        power += note & 1;
        note >>= 1;
    }
    return power;
}

int main() {
    int n;
    scanf("%d", &n);
    int total_beatpower = 0;
    int first_note = 0;
    vector<int> music;
    while (n > total_beatpower) {
        first_note++;
        total_beatpower += beatpower(first_note);
    }
    int current_note = first_note;
    while (current_note > 0) {
        int beatpower_overload = total_beatpower - n;
        if (beatpower(current_note) <= beatpower_overload) {
            // skip this note
            total_beatpower -= beatpower(current_note);
        } else {
            // use this note
            music.push_back(current_note);
        }
        current_note--;
    }
    printf("%zu\n", music.size());
    for (int i : music) {
        printf("%d ", i);
    }
    printf("\n");
    return 0;
}