This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>**//万能头文件
using namespace std;//流操作命名空间
//递归
string dfs(int n){
//返回处理后的字符,一直递归直至全部处理完(0,1,2必须特判跳出);
string out="";//存储输出
int k=-1,i=1;bool ff[16];//临时变量;
//
for(int i=0;i<=15;i++){
ff[i]=n&1;n=n>>1;//二进制取位运算,取得所有的为1的二进位表示可以操作
}
for(int i=15;i>=0;i--){
if(ff[i]){//判断是否为1
if(i>=2)out+="2(" + dfs(i) + ")+";//二以上则再次递归指数
if(i==1)out+="2+";//特判1
if(i==0)out+="2(0)+";//特判0
return out.substr(0,out.size()-1);//返回//去除尾部‘+’
int main(){
int n;cin>>n;
cout<<dfs(n);
return 0;