题目
解题思路
因为题目中说不含有2的0次方,所以奇数要直接输出-1。若n为偶数,就每次减掉在n>=2的m次方的情况下最大的2的m次方,并且输出m。
参考代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 1 << 24;
cin >> n;
if (n & 1) {
cout << -1 << '\n';
} else {
while (n) {
if (n >= x) {
n -= x;
cout << x << ' ';
}
x >>= 1;
}
cout << '\n';
}
return 0;
}