#include<cstdio> #include<algorithm> #include<string> using namespace std; void solve() { int n; scanf("%d", &n); int open = 0; string res = ""; while(n > 0) { if(n % 2 == 1) { if(n == 1) { res += "1"; } else { res += "(1"; open++; } n--; if(n>0) { res += "+"; } } if(n > 0){ res += "(1+1)*"; n = n>>1; } } while(open > 0) { res += ")"; open--; } printf("%s\n", res.c_str()); } int main(int args, char* argv[]) { int t; scanf("%d", &t); for(int i = 0; i < t; i++) solve(); 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 42 43 44 45 46 | #include<cstdio> #include<algorithm> #include<string> using namespace std; void solve() { int n; scanf("%d", &n); int open = 0; string res = ""; while(n > 0) { if(n % 2 == 1) { if(n == 1) { res += "1"; } else { res += "(1"; open++; } n--; if(n>0) { res += "+"; } } if(n > 0){ res += "(1+1)*"; n = n>>1; } } while(open > 0) { res += ")"; open--; } printf("%s\n", res.c_str()); } int main(int args, char* argv[]) { int t; scanf("%d", &t); for(int i = 0; i < t; i++) solve(); return 0; } |