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

const int MAX_N = (int)1e6 + 6;
int dp[MAX_N];

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

    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1] + __builtin_popcount(i);
    }

    vector<int> res;
    int beg = 0, end = n + 1;
    while (n != 0) {
        while (beg + 1 < end) {
            int mid = (beg + end) / 2;
            if (dp[mid] >= n) {
                end = mid;
            } else {
                beg = mid;
            }
        }
        res.push_back(end);
        n -= __builtin_popcount(end);
        beg = 0;
    }

    printf("%d\n", res.size());
    for (int r : res) {
        printf("%d ", r);
    }
    return 0;
}