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
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<fstream>
using namespace std;

vector <int> potegi = {524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1};

int ile_bitow(int a){
    int wyn = 0;
    for(int i = 0; i < 20; i++){
        if(potegi[i] < a){
            a -= potegi[i];
            wyn++;
        }
    }
    return wyn;
}

int main(){
    vector <int> v(1000000);
    int a = 1;
    for(int i = 1; i <= 1000000;){
        int pom = ile_bitow(a);
        for(int j = 0; j < pom; j++){
            v[i] = a;
            i++;
        }
        a++;
    }
    int n;
    cin >> n;
    vector <int> wyn;
    while(n > 0){
        wyn.push_back(v[n]);
        n -= ile_bitow(v[n]);
    }
    cout << wyn.size() << endl;
    for(int i = 0; i < wyn.size();i++){
        cout << wyn[i]-1 << " ";
    }
}