#include <bits/stdc++.h>
using namespace std;
int t[130000];
int main()
{
std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr); std::cout.tie(nullptr);
int sum=0;
for(int i=1; i<130000; ++i)
{
int r=1;
t[i]=i;
while(i>=pow(2, r))
{
t[i]-=floor(i/pow(2, r));
++r;
}
}
int n;
cin>>n;
vector <int> odp;
int i=1;
while(sum<n)
{
odp.push_back(i);
sum+=t[i];
++i;
}
i-=2;
while(sum!=n)
{
if(sum-t[i]>=n)
{
sum-=t[i];
odp.erase(odp.begin()+i-1);
}
i--;
}
cout<<odp.size()<<endl;
for(int j=odp.size()-1; j>=0; --j)
cout<<odp[j]<<" ";
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 | #include <bits/stdc++.h> using namespace std; int t[130000]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr); std::cout.tie(nullptr); int sum=0; for(int i=1; i<130000; ++i) { int r=1; t[i]=i; while(i>=pow(2, r)) { t[i]-=floor(i/pow(2, r)); ++r; } } int n; cin>>n; vector <int> odp; int i=1; while(sum<n) { odp.push_back(i); sum+=t[i]; ++i; } i-=2; while(sum!=n) { if(sum-t[i]>=n) { sum-=t[i]; odp.erase(odp.begin()+i-1); } i--; } cout<<odp.size()<<endl; for(int j=odp.size()-1; j>=0; --j) cout<<odp[j]<<" "; return 0; } |
English