#include
using namespace std;
string run(int x,int i=0,string s=string("")){
if(x==0)return string("0");
do if(x&1)s=(i==1?"2":"2("+run(i)+")")+(s==""?"":"+")+s;//拼接字符串,应题意,要把低次方接在后面
while(++i,x>>=1);//每次向右移位
return s;
}
int main(){
int x;cin>>x;
cout<
#include<bits/stdc++.h>
using namespace std;
string p(int x,int i=0,string a=string(""))
{
if(x==0)
{
return string("0");
}
do
{
if(x&1)
{
a=(i==1?"2":"2("+p(i)+")")+(a==""?"":"+")+a;
}
}
while(++i,x>>=1);
return a;
}
long long aa;
int main()
{
cin>>aa;
cout<<p(aa);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string mcf(int n)
{
if(n==3)return "2+2(0)"; //判断
if(n==2)return "2";
if(n==1)return "2(0)";
int q=log2(n),p=pow(2,q);
if (n==p) return "2("+mcf(q)+")";
else{
return "2("+mcf(q)+")+"+mcf(n-p); //递归
}
}
int main()
{
int n;
cin>>n;
cout<<mcf(n)<<endl;
}
直接递归调用,最后输出就可以了,不用楼上那么麻烦。