#include <iostream> void Print(int k) { if (k == 1) return; if (k & 1) { --k; std::cout << "(1+(1+1)"; if (k > 2) std::cout << "*"; Print(k/2); std::cout << ")"; } else if (k>2) { std::cout << "((1+1)*"; Print(k/2); std::cout << ")"; } else std::cout << "(1+1)"; } void Solve() { int k; std::cin >> k; if (k == 1) std::cout << "1"; else Print(k); std::cout << std::endl; } int main() { int T; std::cin >> T; while (T--) 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 | #include <iostream> void Print(int k) { if (k == 1) return; if (k & 1) { --k; std::cout << "(1+(1+1)"; if (k > 2) std::cout << "*"; Print(k/2); std::cout << ")"; } else if (k>2) { std::cout << "((1+1)*"; Print(k/2); std::cout << ")"; } else std::cout << "(1+1)"; } void Solve() { int k; std::cin >> k; if (k == 1) std::cout << "1"; else Print(k); std::cout << std::endl; } int main() { int T; std::cin >> T; while (T--) Solve(); return 0; } |