//#pragma GCC target("popcnt") #include <ios> int a,b,c,d,e,f,l,k,p,w,n; int pref[1000001],wyn[1000001]; int popcount(int i){ int ret=0; while (i){ ret+=i&1; i>>=1; } return ret; } int main(){ scanf("%d", &n); for (a=1; a<=n; ++a) pref[a]=pref[a-1]+popcount(a); a=n; while (n){ while (pref[a]>=n) --a; wyn[w++]=a+1; n-=popcount(a+1); } printf("%d\n", w); for (a=0; a<w; ++a) printf("%d ", wyn[a]); }
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 | //#pragma GCC target("popcnt") #include <ios> int a,b,c,d,e,f,l,k,p,w,n; int pref[1000001],wyn[1000001]; int popcount(int i){ int ret=0; while (i){ ret+=i&1; i>>=1; } return ret; } int main(){ scanf("%d", &n); for (a=1; a<=n; ++a) pref[a]=pref[a-1]+popcount(a); a=n; while (n){ while (pref[a]>=n) --a; wyn[w++]=a+1; n-=popcount(a+1); } printf("%d\n", w); for (a=0; a<w; ++a) printf("%d ", wyn[a]); } |