#include<cstdio> #include<vector> using namespace std; int t, k; void solve(){ int brackets = 0; printf("1*"); while (k){ if (k == 1){ printf("1"); } else if(k > 1){ if(k & 1){ printf("(1+"); ++brackets; } printf("(1+1)*"); } k >>= 1; } while(brackets--) printf(")"); printf("\n"); } int main(){ scanf ("%d", &t); while(t--){ scanf ("%d", &k); solve(); } }
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 | #include<cstdio> #include<vector> using namespace std; int t, k; void solve(){ int brackets = 0; printf("1*"); while (k){ if (k == 1){ printf("1"); } else if(k > 1){ if(k & 1){ printf("(1+"); ++brackets; } printf("(1+1)*"); } k >>= 1; } while(brackets--) printf(")"); printf("\n"); } int main(){ scanf ("%d", &t); while(t--){ scanf ("%d", &k); solve(); } } |