#include <iostream> #include <algorithm> using namespace std; int tab[100]; int main(){ int t,k; cin>>t; while(t--){ cin>>k; if(k==1){ cout<<"1\n"; }else if(k==2){ cout<<"1+1\n"; }else if(k==3){ cout<<"1+1+1\n"; }else{ int i =0; while(k>1){ if(k%2==1){ tab[i]=1; k-=1; }else{ tab[i]=2; } k/=2; i++; } string wyn = ""; if(tab[i-1]==2){ wyn="1+1"; }else{ wyn="1+1+1"; } for(int j=i-2;j>=0;j--){ if(tab[j]==2){ wyn="("+wyn+")*(1+1)"; }else{ wyn="("+wyn+")*(1+1)+1"; } } cout<<wyn<<"\n"; } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <algorithm> using namespace std; int tab[100]; int main(){ int t,k; cin>>t; while(t--){ cin>>k; if(k==1){ cout<<"1\n"; }else if(k==2){ cout<<"1+1\n"; }else if(k==3){ cout<<"1+1+1\n"; }else{ int i =0; while(k>1){ if(k%2==1){ tab[i]=1; k-=1; }else{ tab[i]=2; } k/=2; i++; } string wyn = ""; if(tab[i-1]==2){ wyn="1+1"; }else{ wyn="1+1+1"; } for(int j=i-2;j>=0;j--){ if(tab[j]==2){ wyn="("+wyn+")*(1+1)"; }else{ wyn="("+wyn+")*(1+1)+1"; } } cout<<wyn<<"\n"; } } return 0; } |