#include <iostream> #include <vector> using namespace std; int main() { int N; cin>>N; int const C = 1000000; int a[C],b[C],T = 0; vector<int> V; for(int i=0; i<C; ++i) { int m = i; int t = 0; while(m > 0) { if(m % 2 == 1) t++; m = m / 2; } T += t; b[i] = t; a[i] = T; } for(int i=C-1; i>0; --i) { if(a[i] >= N && a[i-1] < N) { V.push_back(i); N -= b[i]; } } cout<<V.size()<<endl; for(int i=0; i<V.size(); ++i) cout<<V[i]<<" "; cout<<endl; return 0; }
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 | #include <iostream> #include <vector> using namespace std; int main() { int N; cin>>N; int const C = 1000000; int a[C],b[C],T = 0; vector<int> V; for(int i=0; i<C; ++i) { int m = i; int t = 0; while(m > 0) { if(m % 2 == 1) t++; m = m / 2; } T += t; b[i] = t; a[i] = T; } for(int i=C-1; i>0; --i) { if(a[i] >= N && a[i-1] < N) { V.push_back(i); N -= b[i]; } } cout<<V.size()<<endl; for(int i=0; i<V.size(); ++i) cout<<V[i]<<" "; cout<<endl; return 0; } |