#include<bits/stdc++.h> using namespace std; const int MAXN = 1e6; int p[MAXN+5]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); for(int i=1;i<=MAXN;i++) p[i] = p[i-1] + __builtin_popcount(i); int n; cin >> n; vector<int> t; for(int i=MAXN-1;i>=0;i--) if(p[i] < n) { t.push_back(i+1); n -= __builtin_popcount(i+1); } cout << t.size() << "\n"; for(int i : t) 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 28 29 30 | #include<bits/stdc++.h> using namespace std; const int MAXN = 1e6; int p[MAXN+5]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); for(int i=1;i<=MAXN;i++) p[i] = p[i-1] + __builtin_popcount(i); int n; cin >> n; vector<int> t; for(int i=MAXN-1;i>=0;i--) if(p[i] < n) { t.push_back(i+1); n -= __builtin_popcount(i+1); } cout << t.size() << "\n"; for(int i : t) cout << i << " "; cout << "\n"; return 0; } |