#include <iostream> #include <cstdio> using namespace std; int t, n; void program (int a) { if (a == 2) printf("1+1"); else if (a == 3) printf("1+1+1"); else if (a & 1) { printf("1+(1+1)*("); program(a >> 1); printf(")"); } else { printf("(1+1)*("); program(a >> 1); printf(")"); } } int main () { scanf("%d", &t); while (t--) { scanf("%d", &n); if (n == 1) { printf("1\n"); continue; } program(n); printf("\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 | #include <iostream> #include <cstdio> using namespace std; int t, n; void program (int a) { if (a == 2) printf("1+1"); else if (a == 3) printf("1+1+1"); else if (a & 1) { printf("1+(1+1)*("); program(a >> 1); printf(")"); } else { printf("(1+1)*("); program(a >> 1); printf(")"); } } int main () { scanf("%d", &t); while (t--) { scanf("%d", &n); if (n == 1) { printf("1\n"); continue; } program(n); printf("\n"); } return 0; } |