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
#include <cstdio>
#include <algorithm>

int main() {
    int n;
    scanf("%d", &n);

    int i = 1;
    int j;
    int s = 0;

    while (s < n) {
        s += __builtin_popcount(i);
        i++;
    }

    i--;
    j = i - 1;

    while (j >= 0 && s - __builtin_popcount(j) != n) {
        j--;
    }

    printf("%d\n", i - (j > 0));

    for (; i >= 1; i--) {
        if (j != i)
            printf("%d ", i);
    }

    printf("\n");

    return 0;
}