@[mpsc_001](/user/506039)
把幂次中的10,8,5也变为2进制的
10->2(3)+2->2(2+2(0))+2
8->2(3)->2(2+2(0))
5->2(2)+2(0)
即得样例
2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
by Lazy_Labs @ 2021-07-29 22:56:15
@[a929666](/user/376137) 谢大佬
by mpsc_001 @ 2021-07-30 20:54:49
@[mpsc_001](/user/506039) 不用谢
by Lazy_Labs @ 2021-07-30 22:02:30
@[a929666](/user/376137)
# ~~不要脸地再问一句,输出顺序问题怎么解决啊(无奈)~~
代码:```cpp
#include<iostream>
#include<math.h>
using namespace std;
void b(int n){
int sum=0,s=0;
for(int i=0;sum!=n;i++){
int a=n>>i&1;
if(a==1){sum+=pow(2,i);}
if(s>0&&a!=0) cout<<'+';
if(a!=0){cout<<2;s++;}
if(i!=1&&a!=0){
cout<<'(';
if(i>2) b(i);
else cout<<i;
cout<<')';
}
}
}
int main(){
int n;
cin>>n;
b(n);
return 0;
}
```
by mpsc_001 @ 2021-07-30 22:51:36