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

using namespace std;

int n, a, index, c;
int tab[2][1048576];
vector<int> ans;

int main(){
    tab[0][0] = 0;
    for(int i = 1; i <= 524288; i *= 2){
        for(int j = 0; j < i; j++){
            tab[0][i + j] = tab[0][j] + 1;
        }
    }
    tab[1][0] = 0;
    for(int i = 1; i <= 1000000; i++){
        tab[1][i] = tab[1][i - 1] + tab[0][i];
    }
    scanf("%d", &n);
    index = lower_bound(tab[1], tab[1] + 1000000, n) - tab[1];
    a = tab[1][index] - n;
    c = index;
    for(int i = index; i > 0; i--){
        if(tab[0][i] <= a){
            a -= tab[0][i];
            c--;
        }
        else ans.push_back(i);
    }
    printf("%d\n", c);
    for(auto i : ans){
        printf("%d ", i);
    }
}