提交时间:2024-08-20 16:41:40

运行 ID: 169718

#include<bits/stdc++.h> using namespace std; long long a[16]={1},x,cmp=1; void dfs(int n){ while(n){ for(int i=x;i>=0;i--){ if(a[i]<=n){ n-=a[i]; if(cmp) cmp=0; else cout<<"+"; if(i>1){ cout<<"2("; cmp=1; dfs(i); cout<<")"; break; } if(i==1) cout<<"2"; if(i==0) cout<<"2(0)"; } } } } int main(){ int n; cin>>n; while(a[x]<=n){ x++; a[x]=a[x-1]*2; } dfs(n); return 0; }