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
#include<bits/stdc++.h>
using namespace std;
int sumy[1000010];
int moc[1000010];
int main()
{
	int n, i;
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		for(int j=0;j<20;j++)
			if(i & (1<<j)){
				moc[i] = moc[i-(1<<j)]+1;
				break;
			}
		//printf("%d\n", moc[i]);
		sumy[i] = sumy[i-1]+moc[i];
		if(sumy[i]>=n)
			break;
	}
	int roznica = sumy[i]-n;
	vector<int>odp;
	for(;i>0;i--){
		if(moc[i]<=roznica){
			roznica-=moc[i];
			continue;
		}
		odp.push_back(i);
	}
	printf("%d\n", (int)odp.size());
	for(auto j: odp)
		printf("%d ", j);
}/*
3 2 1
11
10
01
*/