1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<cstdio>
const int N=125005;
int n,i,v[N],sum[N],cnt,q[N];
int main(){
	scanf("%d",&n);
	for(i=1;;i++){
		v[i]=v[i-(i&-i)]+1;
		sum[i]=sum[i-1]+v[i];
		if(sum[i]>=n)break;
	}
	for(;i;i--)if(sum[i-1]<n){
		n-=v[i];
		q[++cnt]=i;
	}
	printf("%d\n",cnt);
	for(i=1;i<=cnt;i++)printf("%d%c",q[i],i<cnt?' ':'\n');
}