#include <bits/stdc++.h> using namespace std; void solve(int a) { int count = 0; while (true) { if (a != 1) { printf("("); count++; } if (a % 2) { printf("1"); if (a != 1) printf("+"); } a /= 2; if (!a) break; printf("(1+1)*"); } while (count--)printf(")"); printf("\n"); } int main() { int t; scanf("%d", &t); while (t--) { int a; scanf("%d", &a); solve(a); } }
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 | #include <bits/stdc++.h> using namespace std; void solve(int a) { int count = 0; while (true) { if (a != 1) { printf("("); count++; } if (a % 2) { printf("1"); if (a != 1) printf("+"); } a /= 2; if (!a) break; printf("(1+1)*"); } while (count--)printf(")"); printf("\n"); } int main() { int t; scanf("%d", &t); while (t--) { int a; scanf("%d", &a); solve(a); } } |