#include <bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
long long cnt=0;
long long sum=0;
for(int i=1; i<=n; i++){
cnt+=__builtin_popcount(i);
if(cnt>=n){
sum=i;
break;
}
}
vector<long long> res;
for(int i=sum; i>=1; i--){
if(cnt-__builtin_popcount(i)>=n){
cnt-=sum;
}
else{
res.push_back(i);
}
}
cout<<res.size()<<endl;
for(auto &a : res){
cout<<a<<" ";
}
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 | #include <bits/stdc++.h> using namespace std; int main(){ long long n; cin>>n; long long cnt=0; long long sum=0; for(int i=1; i<=n; i++){ cnt+=__builtin_popcount(i); if(cnt>=n){ sum=i; break; } } vector<long long> res; for(int i=sum; i>=1; i--){ if(cnt-__builtin_popcount(i)>=n){ cnt-=sum; } else{ res.push_back(i); } } cout<<res.size()<<endl; for(auto &a : res){ cout<<a<<" "; } return 0; } |
English