#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
cin>>n;
int i = 0;
while(n>0) {
n-=__builtin_popcount(i);
i++;
}
--i;
//cout<<i<<endl;
int p=0;
int temp=n;
int z=i;
while (n<0) {
if(n+__builtin_popcount(i)>0) {
//cout<<i<<" ";
p++;
} else {
n+=__builtin_popcount(i);
}
--i;
}
p+=i;
cout<<p<<endl;
while (temp<0) {
if(temp+__builtin_popcount(z)>0) {
cout<<z<<" ";
} else {
temp+=__builtin_popcount(z);
}
--z;
}
while(i>0) {
cout<<i<<" ";
--i;
}
cout<<endl;
}
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 | #include <bits/stdc++.h> using namespace std; int main () { int n; cin>>n; int i = 0; while(n>0) { n-=__builtin_popcount(i); i++; } --i; //cout<<i<<endl; int p=0; int temp=n; int z=i; while (n<0) { if(n+__builtin_popcount(i)>0) { //cout<<i<<" "; p++; } else { n+=__builtin_popcount(i); } --i; } p+=i; cout<<p<<endl; while (temp<0) { if(temp+__builtin_popcount(z)>0) { cout<<z<<" "; } else { temp+=__builtin_popcount(z); } --z; } while(i>0) { cout<<i<<" "; --i; } cout<<endl; } |
English