3483,2的幂次方
作者:
嘎哈哈哈
,
2024-02-16 17:30:57
,
所有人可见
,
阅读 43
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
string dividetwo(int n,int level){
int tmp = n/2;
int mod = n%2;
string res = "";
if(tmp) res += dividetwo(tmp,level+1);
if(mod == 1){
if(tmp!=0) res += "+";
if(level == 1) res += "2";
else if(level <= 2) res += "2("+to_string(level)+")";
else res += "2("+dividetwo(level,0)+")";
}
return res;
}
int main(){
int n;
while(cin>>n){
int idx = 0;
string res = dividetwo(n,0);
cout<<res<<endl;
}
}