#include <iostream>
using namespace std;
#include <cmath>
void Log(int a)
{
int t[16];
for (int i=0;i<=15;i++)
{
t[i]=0;
}
while(a>0)
{
for (int i=0;i<=15;i++)
{
if((a>=pow(2,i)) and (a<pow(2,i+1)))
{
t[i]=1;
a=a-pow(2,i);
}
}
if (a==1)
{
t[0]=1;
}
}
for (int j=15;j>=0;j--)
{
int s;
if (1==t[j])
{
s=0;
for (int k=15;k>j;k--)
{
if (t[k]==1)
{
s=1;
}
}
if (s==0)
{
if (j==0)
{
cout<<"2(0)";
}
else if (j==1)
{
cout<<"2";
}
else if (j==2)
{
cout<<"2(2)";
}
else if (j>2)
{
cout<<"2(";
Log(j);
cout<<")";
}
// cout<<"2("<<j<<")";
}
else if(s==1)
{
if (j==0)
{
cout<<"+2(0)";
}
else if (j==1)
{
cout<<"+2";
}
else if (j==2)
{
cout<<"+2(2)";
}
else if (j>2)
{
cout<<"+2(";
Log(j);
cout<<")";
}
// cout<<"+2("<<j<<")";
}
}
}
}
int main() {
int a;
while (cin >> a) { // 注意 while 处理多个 case
Log(a);
}
}
//初级版本
/*
#include <iostream>
using namespace std;
#include <cmath>
void Log(int a)
{
int t[15];
while(a>0)
{
for (int i=0;i<=15;i++)
{
if((a>=pow(2,i)) and (a<pow(2,i+1)))
{
t[i]=1;
a=a-pow(2,i);
}
}
}
for (int j=15;j>=0;j--)
{
if (1==t[j])
{
cout<<"+2("<<j<<")";
}
}
}
int main() {
int a;
while (cin >> a) { // 注意 while 处理多个 case
Log(a);
}
}
*/

京公网安备 11010502036488号