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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int bin(int a)
{
	int zlicz=0;
	

	while(a>0)
	{
		zlicz+=a%2;
		a=a/2;
		
		
	}
	
	return zlicz;
	
}

int main()
{
	int n; cin>>n;
	int counter=0;
	int li=1;
	int s;
	vector <int> biny(0);
	vector <int> lic(0);
	while(counter<=n)
	{
		s=bin(li);
		biny.push_back(s);
		lic.push_back(li);
		counter+=s;
		li++;
		
		
	}
	int r=counter-n;
	int ind;
	if(r!=0)
	{
		bool ver=true;
		int j=biny.size()-1;
		
		while(ver==true)
		{
			int w=biny[j];
			ind=j;
			j--;
			if(w==r)
			{
				ver=false;
			}
		}
		cout<<biny.size()-1<<endl;
	}
	
	for(int i=lic.size()-1;i>-1;i--)
	{
		if(i!=ind)
		{
			cout<<lic[i]<<" ";
		}
	}
}