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
#include<bits/stdc++.h>
using namespace std;
int n,i=1,ile,s,y,d,pd;
int tab[131072];
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<131072;++i){
		for(int j=0;j<17;++j){
			if(!(i&(1<<j))){
				tab[i^(1<<j)]=tab[i]+1;
			}
		}
	}
	while(s<n)
		{
		s+=tab[i];
		++i;++ile;
	}
	//cout<<s<<"\n";
	y=i-1;
	i-=2;
	while(s>n){
		if(tab[i]<=(s-n)){
			s-=tab[i];
			tab[i]=0;
			--ile;
		}
		--i;
	}
	cout<<ile<<"\n";
	for(;y;--y){
		if(tab[y])cout<<y<<" ";
	}
}