// Just always...
#include <cstdio>
void singleCase() {
int n;
scanf("%d", &n);
if (n < 2) {
printf("1\n");
return;
}
int i = 1, ones = -1;
while (i <= n) {
if (i & n)
++ones;
i <<= 1;
}
for (int j = 0; j < ones; ++j)
putchar('(');
printf("(1+1)");
i >>= 2;
if (i & n)
printf("+1)");
i >>= 1;
while (i) {
printf("*(1+1)");
if (i & n)
printf("+1)");
i >>= 1;
}
putchar('\n');
}
int main() {
int t;
scanf("%d", &t);
++t;
while (--t)
singleCase();
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 | // Just always... #include <cstdio> void singleCase() { int n; scanf("%d", &n); if (n < 2) { printf("1\n"); return; } int i = 1, ones = -1; while (i <= n) { if (i & n) ++ones; i <<= 1; } for (int j = 0; j < ones; ++j) putchar('('); printf("(1+1)"); i >>= 2; if (i & n) printf("+1)"); i >>= 1; while (i) { printf("*(1+1)"); if (i & n) printf("+1)"); i >>= 1; } putchar('\n'); } int main() { int t; scanf("%d", &t); ++t; while (--t) singleCase(); return 0; } |
English