#include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int res = 0; while(n > 0) { res++; n -= __builtin_popcount(res); } vector<int> ans; n = -n; for(int i=res;i>0;i--) { if(__builtin_popcount(i) <= n) n -= __builtin_popcount(i); else ans.push_back(i); } cout << ans.size() << '\n'; for(auto v : ans) cout << v << ' '; cout << '\n'; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int res = 0; while(n > 0) { res++; n -= __builtin_popcount(res); } vector<int> ans; n = -n; for(int i=res;i>0;i--) { if(__builtin_popcount(i) <= n) n -= __builtin_popcount(i); else ans.push_back(i); } cout << ans.size() << '\n'; for(auto v : ans) cout << v << ' '; cout << '\n'; } |