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
#include <bits/stdc++.h>
using namespace std;
int n,lc,sum,il,mks;
queue<int>q;
int main()
{
	cin>>n;
	lc=1;
	while(sum<n)
	{
		sum+=__builtin_popcount(lc);
		lc++;
	}
	lc--;
	il=lc;
	mks=lc;
	while(sum>n)
	{
		if(__builtin_popcount(lc)<=sum-n)
		{
			q.push(lc);
			//cout<<lc<<"\n";
			sum-=__builtin_popcount(lc);
			il--;
		}
		lc--;
	}
	cout<<il<<"\n";
	for(int i=mks; i>=1; i--)
	{
		if(i!=q.front())
		{
			cout<<i<<" ";
			
		}
		else
			q.pop();
	}
	cout<<"\n";
}