蒟蒻自学的递归,满江红
#include<iostream>
using namespace std;
int p[16],x;
bool first=true;
void power2(int n)
{
while(n)
for(int i=x;i>=0;i--)
{
if(n>=p[i])
{
n-=p[i];
if(first)first=false;
else cout<<"+";
if(i>1)
{
first=true;
cout<<"2(";
power2(i);
cout<<")";
break;
}
}
if(i==0)cout<<"2(0)";
if(i==1)cout<<"2";
}
}
int main()
{
int n;
p[0]=1;
cin>>n;
while(p[x]<=n)
{
x++;
p[x]=p[x-1]*2;
}
power2(n);
return 0;
}
这里是记录