#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
int sum = 0; int l = 0;
while(sum < n){
l++;
sum += __builtin_popcount(l);
}
int roz = sum - n;
bool czy = false;
if(roz)
cout << l-1 << '\n';
else
cout << l << '\n';
for(int i = l; i > 0; i--){
if(!czy)
if(__builtin_popcount(i) == roz){
czy = 1; continue;
}
cout << i << ' ';
}
cout << '\n';
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 | #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int sum = 0; int l = 0; while(sum < n){ l++; sum += __builtin_popcount(l); } int roz = sum - n; bool czy = false; if(roz) cout << l-1 << '\n'; else cout << l << '\n'; for(int i = l; i > 0; i--){ if(!czy) if(__builtin_popcount(i) == roz){ czy = 1; continue; } cout << i << ' '; } cout << '\n'; return 0; } |
English