#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ int t; scanf("%d", &t); while (t--){ int n; scanf("%d", &n); int parens = 0; bool start = true; while (n > 1) { if (!start) { printf("("); parens ++; } start = false; if (n % 2 == 1) { printf("1+"); n -= 1; } else { printf("(1+1)*"); n /= 2; } } printf("1"); while (parens--) { printf(")"); } 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 | #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ int t; scanf("%d", &t); while (t--){ int n; scanf("%d", &n); int parens = 0; bool start = true; while (n > 1) { if (!start) { printf("("); parens ++; } start = false; if (n % 2 == 1) { printf("1+"); n -= 1; } else { printf("(1+1)*"); n /= 2; } } printf("1"); while (parens--) { printf(")"); } printf("\n"); } return 0; } |