题目要求将 n n n 拆分成若干个不同的 2 2 2 的幂。显然,根据二进制的唯一分解性,可知只有一种拆分方法
不能拆出 2 0 2^0 20,显然就是要满足 n n n 为偶数
然后这题就做完了
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long n;
inline long long read()
{
long long s=0,w=1;
char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-')w=-1;ch=getchar();}
while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return s*w;
}
int main()
{
// freopen("power.in","r",stdin);
// freopen("power.out","w",stdout);
n=read();
if(n & 1ll){
puts("-1");return 0;}
for(long long i=(long long)30;i>=(long long)0;--i)
if(n & (1ll<<i))printf("%lld ",(1ll<<i));
putchar('\n');
return 0;
}