#include <iostream> #include <string> std::string oneify(int& k) { if (k == 1) { return "1"; } else if (k == 2) { return "1+1"; } else if (k == 3) { return "1+1+1"; } int res = k % 2; k /= 2; if (res) { return "1+(1+1)*(" + oneify(k) + ")"; } else { return "(1+1)*(" + oneify(k) + ")"; } } int main() { std::ios_base::sync_with_stdio(0); int t, k; std::cin >> t; while (t--) { std::cin >> k; std::cout << oneify(k) << std::endl; } 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 | #include <iostream> #include <string> std::string oneify(int& k) { if (k == 1) { return "1"; } else if (k == 2) { return "1+1"; } else if (k == 3) { return "1+1+1"; } int res = k % 2; k /= 2; if (res) { return "1+(1+1)*(" + oneify(k) + ")"; } else { return "(1+1)*(" + oneify(k) + ")"; } } int main() { std::ios_base::sync_with_stdio(0); int t, k; std::cin >> t; while (t--) { std::cin >> k; std::cout << oneify(k) << std::endl; } return 0; } |