#include<iostream>
using namespace std;
const int limit=1e6+7;
bool wzieta[limit];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
int i;
int ile=0;
for(i=1; i<limit; i++){
n-=__builtin_popcount(i);
wzieta[i]=1;
ile++;
if(n<=0){
break;
}
}
for(; i; i--){
if(n+__builtin_popcount(i)<=0){
n+=__builtin_popcount(i);
wzieta[i]=0;
ile--;
}
}
cout<<ile<<'\n';
for(i=limit-1; i; i--){
if(wzieta[i]){
cout<<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 30 31 32 33 | #include<iostream> using namespace std; const int limit=1e6+7; bool wzieta[limit]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; int i; int ile=0; for(i=1; i<limit; i++){ n-=__builtin_popcount(i); wzieta[i]=1; ile++; if(n<=0){ break; } } for(; i; i--){ if(n+__builtin_popcount(i)<=0){ n+=__builtin_popcount(i); wzieta[i]=0; ile--; } } cout<<ile<<'\n'; for(i=limit-1; i; i--){ if(wzieta[i]){ cout<<i<<' '; } } } |
English