#include <bits/stdc++.h> using namespace std; int in[1000005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int s=0; for(int i=1;i<=n;i++) { s+=__builtin_popcount(i); in[i]=1; if(s>=n) break; } for(int i=n;i>=1;i--) if(in[i]&&s-__builtin_popcount(i)>=n) in[i]=0,s-=__builtin_popcount(i); int cnt=0; for(int i=n;i>=1;i--) cnt+=in[i]; cout << cnt << "\n"; for(int i=n;i>=1;i--) if(in[i]) cout << 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 | #include <bits/stdc++.h> using namespace std; int in[1000005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int s=0; for(int i=1;i<=n;i++) { s+=__builtin_popcount(i); in[i]=1; if(s>=n) break; } for(int i=n;i>=1;i--) if(in[i]&&s-__builtin_popcount(i)>=n) in[i]=0,s-=__builtin_popcount(i); int cnt=0; for(int i=n;i>=1;i--) cnt+=in[i]; cout << cnt << "\n"; for(int i=n;i>=1;i--) if(in[i]) cout << i << " "; return 0; } |