#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int MB[1000007];
vector<int> wyn;
void moc(){
for (int i=0; i<1007; i++){
int x=i;
int pot=1<<10;
while (x>0){
//cout<<i<<" "<<x<<" "<<pot<<"\n";
if (pot<=x){
x-=pot;
MB[i]++;
}
pot/=2;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int M; cin>>M;
moc();
//for (int i=0; i<100; i++) cout<<MB[i];
int x=0;
int i=0;
while (x<M){
i++;
x+=MB[i];
}
//cout<<i<<endl;
while(x>M){
if (MB[i]<=x-M){
x-=MB[i];
//cout<<"-"<<i<<endl;
}
else{
wyn.push_back(i);
}
i--;
}
while(i>0){
wyn.push_back(i);
i--;
}
cout<<wyn.size()<<"\n";
for (int i=0; i<wyn.size(); i++) cout<<wyn[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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include<iostream> #include<algorithm> #include<vector> using namespace std; int MB[1000007]; vector<int> wyn; void moc(){ for (int i=0; i<1007; i++){ int x=i; int pot=1<<10; while (x>0){ //cout<<i<<" "<<x<<" "<<pot<<"\n"; if (pot<=x){ x-=pot; MB[i]++; } pot/=2; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int M; cin>>M; moc(); //for (int i=0; i<100; i++) cout<<MB[i]; int x=0; int i=0; while (x<M){ i++; x+=MB[i]; } //cout<<i<<endl; while(x>M){ if (MB[i]<=x-M){ x-=MB[i]; //cout<<"-"<<i<<endl; } else{ wyn.push_back(i); } i--; } while(i>0){ wyn.push_back(i); i--; } cout<<wyn.size()<<"\n"; for (int i=0; i<wyn.size(); i++) cout<<wyn[i]<<" "; } |
English