#include <iostream> using namespace std; int tab[1000000]; int kol[1000000]; int x, y, z, a, b, n, p; int main(){ cin >> n; tab[1]=1; tab[2]=1; p=1; z=1; x=0; while (n>0){ x++; if (x==z){ z*=2; tab[x]=1; } else { tab[x]=tab[x-(z/2)]+1; } n-=tab[x]; } y=1; while (x>0){ if (n<=0){ if (n+tab[x]<=0){ n+=tab[x]; } else { kol[y]=x; y++; } } x--; } y--; cout << y << '\n'; for (int i=1; i<=y; i++){ cout << kol[i] << " "; } }
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 | #include <iostream> using namespace std; int tab[1000000]; int kol[1000000]; int x, y, z, a, b, n, p; int main(){ cin >> n; tab[1]=1; tab[2]=1; p=1; z=1; x=0; while (n>0){ x++; if (x==z){ z*=2; tab[x]=1; } else { tab[x]=tab[x-(z/2)]+1; } n-=tab[x]; } y=1; while (x>0){ if (n<=0){ if (n+tab[x]<=0){ n+=tab[x]; } else { kol[y]=x; y++; } } x--; } y--; cout << y << '\n'; for (int i=1; i<=y; i++){ cout << kol[i] << " "; } } |