#include<bits/stdc++.h> using namespace std; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, x = 0, a; cin>>n; for(int i=1; i<=n; i++) { if(x >= n) break; v.push_back(i); x += __builtin_popcount(i); } m = v.size(); for(int i=v.size()-1; i>=0; i--) { a = __builtin_popcount(v[i]); if(x - a >= n) { x -= a; v[i] = -1; m--; } } cout<<m<<"\n"; for(int i=v.size()-1; i>=0; i--) if(v[i] != -1) cout<<v[i]<<" "; 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<bits/stdc++.h> using namespace std; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, x = 0, a; cin>>n; for(int i=1; i<=n; i++) { if(x >= n) break; v.push_back(i); x += __builtin_popcount(i); } m = v.size(); for(int i=v.size()-1; i>=0; i--) { a = __builtin_popcount(v[i]); if(x - a >= n) { x -= a; v[i] = -1; m--; } } cout<<m<<"\n"; for(int i=v.size()-1; i>=0; i--) if(v[i] != -1) cout<<v[i]<<" "; return 0; } |