题解:P7071 [CSP-J 2020] 优秀的拆分
lailai0916 · · 题解
解题思路
显然 -1。
若
因此用 1<<31-__builtin_clz(n) 取出当前
参考代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
if(n&1)
{
cout<<-1<<'\n';
return 0;
}
while(n)
{
int t=1<<31-__builtin_clz(n);
cout<<t<<' ';
n-=t;
}
return 0;
}