原题传送门
#include <iostream>
#include <cmath>
using namespace std;
void work(int n)
{
if (n == 0)
{
return;
}
int maxx = log2(n);//寻找小于n的最大的二次幂
if (maxx == 0)
{
cout << "2(0)";
}
if (maxx == 1)
{
cout << "2";
}
if (maxx >= 2)//超过一继续分解
{
cout << "2(";
work(maxx);
cout << ")";
}
if (pow(2, maxx) != n)//分解剩下的
{
cout << "+";
work(n - pow(2, maxx));
}
}
int main()
{
int n;
cin >> n;
work(n);
}