#include<bits/stdc++.h> using namespace std; using ll=long long; int n; vector<int>t; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n; int s=0; int i=0; for(i=1;;++i){ s+=__builtin_popcount(i); if(s>=n) break; } for(;i>=1;--i){ if(s-__builtin_popcount(i)>=n) s-=__builtin_popcount(i); else t.push_back(i); } cout<<t.size()<<'\n'; for(i=0;i<t.size();++i) cout<<t[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 | #include<bits/stdc++.h> using namespace std; using ll=long long; int n; vector<int>t; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n; int s=0; int i=0; for(i=1;;++i){ s+=__builtin_popcount(i); if(s>=n) break; } for(;i>=1;--i){ if(s-__builtin_popcount(i)>=n) s-=__builtin_popcount(i); else t.push_back(i); } cout<<t.size()<<'\n'; for(i=0;i<t.size();++i) cout<<t[i]<<' '; } |