#include <stdio.h>
#include <string.h>
char res[500];
int main() {
int t, k;
scanf("%d", &t);
while (t--) {
scanf("%d", &k);
char *r = res;
int par = 0;
while (k > 1) {
if (k%2) r = strcpy(r, "(1+")+3, par++;
r = strcpy(r, "(1+1)*")+6;
k /= 2;
}
r = strcpy(r, "1")+1;
while (par--) *(r++) = ')';
*r = 0;
printf("%s\n", res);
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> #include <string.h> char res[500]; int main() { int t, k; scanf("%d", &t); while (t--) { scanf("%d", &k); char *r = res; int par = 0; while (k > 1) { if (k%2) r = strcpy(r, "(1+")+3, par++; r = strcpy(r, "(1+1)*")+6; k /= 2; } r = strcpy(r, "1")+1; while (par--) *(r++) = ')'; *r = 0; printf("%s\n", res); } return 0; } |
English