#include<iostream> #include<vector> using namespace std; typedef long long ll; ll t[35]; vector<ll>v; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,wyz=0,x=1,sum=0; cin>>n; while(sum<n){ sum+=__builtin_popcount(x); t[__builtin_popcount(x)]=x; v.push_back(x); x++; } if(sum>n)wyz=t[sum-n]; cout<<v.size()-((wyz!=0)?1:0)<<'\n'; for(int i=v.size()-1;i>=0;i--){ if(v[i]!=wyz)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 | #include<iostream> #include<vector> using namespace std; typedef long long ll; ll t[35]; vector<ll>v; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,wyz=0,x=1,sum=0; cin>>n; while(sum<n){ sum+=__builtin_popcount(x); t[__builtin_popcount(x)]=x; v.push_back(x); x++; } if(sum>n)wyz=t[sum-n]; cout<<v.size()-((wyz!=0)?1:0)<<'\n'; for(int i=v.size()-1;i>=0;i--){ if(v[i]!=wyz)cout<<v[i]<<' '; } return 0; } |