Files
ExerciseHub/Luogu/P1010 [NOIP1998 普及组] 幂次方.cpp
2025-08-13 21:38:49 +08:00

52 lines
1.1 KiB
C++

#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
string flag(int in){
if(in==15) return "2(2+2(0))+2(2)+2+2(0)";
else if(in==14) return "2(2+2(0))+2(2)+2";
else if(in==13) return "2(2+2(0))+2(2)+2(0)";
else if(in==12) return "2(2+2(0))+2(2)";
else if(in==11) return "2(2+2(0))+2+2(0)";
else if(in==10) return "2(2+2(0))+2";
else if(in==9) return "2(2+2(0))+2(0)";
else if(in==8) return "2(2+2(0))";
else if(in==7) return "2(2)+2+2(0)";
else if(in==6) return "2(2)+2";
else if(in==5) return "2(2)+2(0)";
else if(in==4) return "2(2)";
else if(in==3) return "2+2(0)";
else if(in==2) return "2";
else return "";
}
int main(){
int n;
cin>>n;
int a[16]={0},b[16]={-1},c[16]={-1},d[16]={-1};
for(int j=0;j<16;j++){
a[j]=pow(2,j);
}
int tmp=n;
int i=15,js=0;
while(tmp!=0){
if(tmp>=a[i]){
tmp-=a[i];
b[js]=i;
js++;
}
i--;
}
for(int j=0;j<js;j++){
if(b[j]!=0&&b[j]!=1) cout<<"2("<<flag(b[j])<<")";
if(b[j]==1) cout<<"2";
if(b[j]==0) cout<<"2(0)";
if(j!=(js-1)){
cout<<"+";
}
}
return 0;
}