2的幂次方
原题链接:4688.挖钻石2023-08-13 16:11:23
发布于:广东
#include<iostream>
#include<cmath>
using namespace std;
int a;
void f(int x)
{
for(int i=14;i>=0;i--)
{
if(pow(2,i)<=x){
if(i==1) cout<<"2";
else if(i==0) cout<<"2(0)";
else{
cout<<"2(";
f(i);
cout<<")";
}
x-=pow(2,i);
if(x!=0) cout<<"+";
}
}
}
int main()
{
cin>>a;
f(a);
return 0;
}
这里空空如也
有帮助,赞一个