@[Problem1613end](/user/1281623)
借你看一下我的代码,大概跟你差不多吧
```cpp
#include<bits/stdc++.h>
using namespace std;
void work(int n)
{
if(n>2)
{
int js=0,x=n;
while(x>=2)
{
js++;
x/=2;
}
if(js>1)
{
cout<<"2(";
work(js);
cout<<")";
}
else
{
cout<<2;
}
x=1;
for(int i=1;i<=js;i++)
{
x*=2;
}
if(n-x!=0)
{
cout<<'+';
work(n-x);
}
}
else if(n==1)
{
cout<<"2(0)";
return;
}
else
{
cout<<2;
}
}
int main()
{
int n;
cin>>n;
work(n);
return 0;
}
``````
by ycy1124 @ 2024-02-22 11:34:28
@[Problem1613end](/user/1281623)
你的a数组好像开小了,n的范围是2×10的四次方
by ycy1124 @ 2024-02-22 11:36:50
@[Problem1613end](/user/1281623)
改成这样就OK了
```cpp
#include<iostream>
using namespace std;
long long n,a[20]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
long long sss(int c){
for(int b=15;b>=0;b--){
if(c>=a[b]){
c=c-a[b];
if(b==1){
cout<<"2";
}
else{
if(b==0) cout<<"2(0)";
else{
cout<<"2(";
sss(b);
cout<<")";
}
}
if(c!=0) cout<<"+";
else return 0;
}
}
return 0;
}
int main(){
cin>>n;
sss(n);
return 0;
}
``````
by ycy1124 @ 2024-02-22 11:39:15
@[ycy1124](/user/1199534) Thanks
by Problem1613end @ 2024-02-22 12:46:09