Problem Statement
题目链接
C++ Code
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
LL POW(int x) {
LL res = 1;
for(int i = 1; i <= x; i ++) res = res * 2;
return res;
}
int main() {
LL N;
cin >> N;
vector<int> s;
while(N != 0) {
s.pb(N % 2);
N /= 2;
}
vector<int> num;
for(int i = 0; i < s.size(); i ++) {
if(s[i] == 1) num.pb(i);
}
int k = (int)num.size();
LL res;
LL M = (1 << k);
for(int i = 0; i < M; i ++) {
res = 0;
for(int j = 0; j < k; j ++) {
if(i >> j & 1) res += POW(num[j]);
}
cout << res << '\n';
}
return 0;
}