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
44
45
46
47
48
49
50
#include<iostream>
#include <stdio.h>
#include<vector>
using namespace std;
int T[1000007];
int W = 1000007;

int bs(int l, int p, int x)
{
    //cout<<"START\n";
    while(l<p)
    {
        int mid = (l+p)/2;
        //cout << mid << "\n";
        if(T[mid] >= x)
        {
            p = mid;
        }
        else
        {
            l = mid + 1;
        }
    }
    return p;
}

int main()
{
    T[1] = 1; //cout<<1 <<" ";
    for(int i = 2; i <= W; i++)
    {
        T[i] = T[i-1] + __builtin_popcount(i);
        //cout<<T[i] << " ";
    }

    int n; cin>>n;
    vector<int> V;
    while(n != 0)
    {
        int liczba = bs(1,W,n);
        V.push_back(liczba);
        n -= __builtin_popcount(liczba);
    }
    cout<<V.size() << "\n";
    for(int i = 0; i < V.size(); i++)
    {
        cout<<V[i] << " ";
    }
    return 0;
}