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
51
#include<bits/stdc++.h>
using namespace std;
int tab[1000005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,ile=0,i=0,g=0,ilei=0;
    cin>>n;
    tab[0]=-1;
    //cout<<"-";
    while(ile<n)
    {
        i++;
        ilei++;
        // cout<<"+"<<endl;
        g=__builtin_popcountl(i);
        ile+=g;
        tab[i]=g;


    }
    //cout<<i;
    int j=i-1;
    int delta=ile-n;
    //cout<<delta<<endl;
    while(delta>0)
    {
        //cout<<"="<<endl;
        if(tab[j]<=delta)
        {
            delta-=tab[j];
            tab[j]=-1;
            ilei--;
        }
        j--;
    }
    cout<<ilei<<'\n';
    for(int k=i;k>=1;k--)
    {
        if(tab[k]!=-1)
        {
            cout<<k<<" ";
        }
    }





}