/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll q=1048577;
ll n,t[q];
ll zamien(ll n){
ll k=0;
while(n!=0){
k+=n%2;
n/=2;
}
return k;
}
int main()
{
cin>>n;
ll po=1, licz=0, sum=1;
while(sum<n){
po*=2;
sum+=sum+po;
//cout<<sum<<" "<<po<<"\n";
}
licz=0;
po=2*po-1; ll p1=po;
ll k=sum-n;
//cout<<k;
while(k!=0){
ll a=zamien(po);
if(a<=k){
k-=a;
licz++;
t[po]=1;
}
po--;
}
cout<<p1-licz<<"\n";
for(int i=p1; i>=1; i--){
if(t[i]==0)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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> #define ll long long using namespace std; const ll q=1048577; ll n,t[q]; ll zamien(ll n){ ll k=0; while(n!=0){ k+=n%2; n/=2; } return k; } int main() { cin>>n; ll po=1, licz=0, sum=1; while(sum<n){ po*=2; sum+=sum+po; //cout<<sum<<" "<<po<<"\n"; } licz=0; po=2*po-1; ll p1=po; ll k=sum-n; //cout<<k; while(k!=0){ ll a=zamien(po); if(a<=k){ k-=a; licz++; t[po]=1; } po--; } cout<<p1-licz<<"\n"; for(int i=p1; i>=1; i--){ if(t[i]==0)cout<<i<<" "; } return 0; } |
English