#include<bits/stdc++.h>
using namespace std;
int pot[31];
void f(){
int k,k1,pier; scanf("%d", &k); k1=k;
int t[31];
t[0] = 0;
for(int i=30;i>=0;i--){
t[i] = 0;
if(k1>=pot[i]) {
//cout<<k1<<" "<<i<<endl;
t[i] = 1;
k1-=pot[i];
}
}
int ile=0,ost;
for(int i=0;i<31;i++) if(t[i]==1) ost=i;
for(int i=0;i<ost;i++){
if(i == ost-1){
if(t[i] == 1) {
if(i==0) printf("(1+(1+1)");
else printf("(1+(1+1)");
ile++;
}
else{
printf("(1+1)");
}
}
else{
if(t[i] == 1) {
if(i==0) printf("(1+(1+1)*");
else printf("(1+(1+1)*");
ile++;
}
else{
printf("(1+1)*");
}
}
}
for(int i=0;i<ile;i++) printf(")");
if(k==1) printf("1");
printf("\n");
}
int main(){
pot[0] = 1;
for(int i=1;i<=30;i++) pot[i] = pot[i-1]*2;
int testy; scanf("%d", &testy);
while(testy--) f();
}
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 48 49 50 51 52 53 | #include<bits/stdc++.h> using namespace std; int pot[31]; void f(){ int k,k1,pier; scanf("%d", &k); k1=k; int t[31]; t[0] = 0; for(int i=30;i>=0;i--){ t[i] = 0; if(k1>=pot[i]) { //cout<<k1<<" "<<i<<endl; t[i] = 1; k1-=pot[i]; } } int ile=0,ost; for(int i=0;i<31;i++) if(t[i]==1) ost=i; for(int i=0;i<ost;i++){ if(i == ost-1){ if(t[i] == 1) { if(i==0) printf("(1+(1+1)"); else printf("(1+(1+1)"); ile++; } else{ printf("(1+1)"); } } else{ if(t[i] == 1) { if(i==0) printf("(1+(1+1)*"); else printf("(1+(1+1)*"); ile++; } else{ printf("(1+1)*"); } } } for(int i=0;i<ile;i++) printf(")"); if(k==1) printf("1"); printf("\n"); } int main(){ pot[0] = 1; for(int i=1;i<=30;i++) pot[i] = pot[i-1]*2; int testy; scanf("%d", &testy); while(testy--) f(); } |
English