#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
vector<int>pc(n+1);
for (int i=1; i<=n; i++) pc[i]=pc[i>>1]+(i&1);
partial_sum(pc.begin(), pc.end(), pc.begin());
int k=n;
vector<int>ans;
while (n)
{
if (pc[k-1] < n)
{
n-=(pc[k]-pc[k-1]);
ans.push_back(k);
}
k--;
}
cout<<ans.size()<<"\n";
for (auto i : ans) cout<<i<<" ";
cout<<"\n";
}
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 main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<int>pc(n+1); for (int i=1; i<=n; i++) pc[i]=pc[i>>1]+(i&1); partial_sum(pc.begin(), pc.end(), pc.begin()); int k=n; vector<int>ans; while (n) { if (pc[k-1] < n) { n-=(pc[k]-pc[k-1]); ans.push_back(k); } k--; } cout<<ans.size()<<"\n"; for (auto i : ans) cout<<i<<" "; cout<<"\n"; } |
English