#include<bits/stdc++.h>
using namespace std;
#define nd second
#define st first
#define pb push_back
typedef long long ll;
typedef long double ld;
const int N = 1000 * 1000 + 7;
void Solve()
{
int n, l, s; vector<int> ans;
cin >> n;
l = 0; s = 0;
while(s < n)
{
++l; s += __builtin_popcount(l);
}
s = s - n;
for(int i = l; i >= 1; --i)
{
//cout << i << " " << __builtin_popcount(i) << " " << s << "\n";
if(__builtin_popcount(i) <= s)
s -= __builtin_popcount(i);
else
ans.pb(i);
}
cout << ans.size() << "\n";
for(int i = 0; i < (int)ans.size(); ++i)
cout << ans[i] << " ";
cout << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
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 | #include<bits/stdc++.h> using namespace std; #define nd second #define st first #define pb push_back typedef long long ll; typedef long double ld; const int N = 1000 * 1000 + 7; void Solve() { int n, l, s; vector<int> ans; cin >> n; l = 0; s = 0; while(s < n) { ++l; s += __builtin_popcount(l); } s = s - n; for(int i = l; i >= 1; --i) { //cout << i << " " << __builtin_popcount(i) << " " << s << "\n"; if(__builtin_popcount(i) <= s) s -= __builtin_popcount(i); else ans.pb(i); } cout << ans.size() << "\n"; for(int i = 0; i < (int)ans.size(); ++i) cout << ans[i] << " "; cout << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solve(); return 0; } |
English