#include<cstdio> #include<string> std::string answerForNumber(int x) { if (x % 2 == 0 && x > 2) { return "(" + answerForNumber(x / 2) + ")*(1+1)"; } else if (x > 1) { return answerForNumber(x - 1) + "+1"; } else { return "1"; } } int main() { int t; scanf("%d", &t); while (t--) { int k; scanf("%d", &k); printf("%s\n", answerForNumber(k).c_str()); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<cstdio> #include<string> std::string answerForNumber(int x) { if (x % 2 == 0 && x > 2) { return "(" + answerForNumber(x / 2) + ")*(1+1)"; } else if (x > 1) { return answerForNumber(x - 1) + "+1"; } else { return "1"; } } int main() { int t; scanf("%d", &t); while (t--) { int k; scanf("%d", &k); printf("%s\n", answerForNumber(k).c_str()); } } |