提交时间:2024-08-20 14:17:09
运行 ID: 168887
#include<iostream> #include<string> using namespace std; string b[20]={"2(0)","2","2(2)","2(2+2(0))","2(2(2))","2(2(2)+2(0))","2(2(2)+2)","2(2(2)+2+2(0))","2(2(2+2(0)))","2(2(2+2(0))+2(0))","2(2(2+2(0))+2)","2(2(2+2(0))+2+2(0))","2(2(2+2(0))+2(2))","2(2(2+2(0))+2(2)+2(0))","2(2(2+2(0))+2(2)+2)","2(2(2+2(0))+2(2)+2+2(0))"}; int n,x[20],step=-1,first=2e9; int main() { cin>>n; while(n>=1) { step++; if(n%2==1) { first=min(first,step); x[step]=1; } n/=2; } for(int i=step;i>=0;i--) { if(x[i]==1) { if(i==first) { cout<<b[i]; } else { cout<<b[i]<<"+"; } } } return 0; }