写的有点问题
```
#include<bits/stdc++.h>
using namespace std;
int n,a[33]={1};
void o(int k) {
if(k==1) {
printf("2(0)");
return;
}
if(k==2) {
printf("2");
return;
}
for(int i=1;i<=22;i++) {
if(a[i]<=k&&a[i+1]>k) {
printf("2");
if(i!=1) {
printf("(");
o(i);
printf(")");
}
if(k>a[i]) {
printf("+");
o(k-a[i]);
return;
}
}
}
}
int main() {
scanf("%d",&n);
for(int i=1;i<=22;i++) a[i]=2*a[i-1];
o(n);
return 0;
}
```
你可以参考一下
by melons_sundae @ 2022-10-21 18:09:10
@[Li_mz__](/user/765987)
```
if(b==1)
{
cout<<'2';
}
```
或者你直接
```
if(!b){
cout<<"2(0)";
}
else if(b==1){
cout<<"2";
}
else{
cout<<"2(";
f(b);
cout<<")";
}
by xxc123 @ 2023-04-10 22:03:34
求关注
by xxc123 @ 2023-04-10 22:04:25