#include <bits/stdc++.h> using namespace std; bool desc(long long p1, long long p2) { return p1 > p2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n , max_m , suma=0; cin >> n; set <long long> s; for(int i=1;;i++) { s.insert(i); suma+=__builtin_popcount(i); if(suma >= n) { max_m = i; break; } } while(suma-n > 0) { if((suma-n)-__builtin_popcount(max_m) >= 0) { s.erase(max_m); suma-=__builtin_popcount(max_m); } max_m--; } vector <long long> v; cout << s.size() << "\n"; for(set<long long>::iterator i = s.begin(); i != s.end(); i++){ v.push_back(*i); } sort(v.begin(),v.end() , desc); for(int i=0;i<v.size();i++) { cout << v[i] << " "; } 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <bits/stdc++.h> using namespace std; bool desc(long long p1, long long p2) { return p1 > p2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n , max_m , suma=0; cin >> n; set <long long> s; for(int i=1;;i++) { s.insert(i); suma+=__builtin_popcount(i); if(suma >= n) { max_m = i; break; } } while(suma-n > 0) { if((suma-n)-__builtin_popcount(max_m) >= 0) { s.erase(max_m); suma-=__builtin_popcount(max_m); } max_m--; } vector <long long> v; cout << s.size() << "\n"; for(set<long long>::iterator i = s.begin(); i != s.end(); i++){ v.push_back(*i); } sort(v.begin(),v.end() , desc); for(int i=0;i<v.size();i++) { cout << v[i] << " "; } return 0; } |