You are given a non-negative integer NN. Print all non-negative integers xx that satisfy the following condition in ascending order.
- The set of the digit positions containing 11 in the binary representation of xx is a subset of the set of the digit positions containing 11 in the binary representation of NN.
- That is, the following holds for every non-negative integer kk: if the digit in the "2^k2ks" place of xx is 11, the digit in the 2^k2ks place of NN is 11
题意:给你一个数n,他的二进制表示的所有1的位数的集合是s ,求满足二进制表示的所有的1的位数的集合是s的子集的数
思路:先把每一位1放进一个数组里,下标想从0开始,看看有几位,然后状态压缩,转换成二进制一个一个枚举每一位选或不选的状态
比如:有4位,那么我们就令所有状态为op=1<<4,然后从0到op-1枚举i,看i的每一位是不是1,如果是1的话就说明选了哪一位,最后看所有选的数加起来是多少就行
/*
.----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ________ | || | _________ | || | ____ ____ | || | ____ | |
| | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
| | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
| | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
| | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
| | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b){
return b>0 ? gcd(b,a%b):a;
}
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
//int e[N],ne[N],h[N],idx,w[N];
/*void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
*/
const int N=2e5+10;
int n;
int a[N];
int f[65];
void init(){
f[0]=1;
for(int i=1;i<=60;i++){
f[i]=f[i-1]*2;
}
}
void sove(){
cin>>n;
int k=0,con=0;
while(n){
if(n&1)a[con++]=f[k];
k++;
n>>=1;
}
// cout<<con<<endl;
int num=1<<con;
// cout<<num<<endl;
for(int i=0;i<num;i++){
int x=i,cnt=0;
int ans=0;
while(x){
if(x&1)ans+=a[cnt];
cnt++;
x>>=1;
}
cout<<ans<<endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie() ,cout.tie() ;
int t=1;
init();
// cin>>t;
while(t--){
sove();
}
return 0;
}