#include <iostream> using namespace std; string create_string(int number) { if (number == 2) return "1+1"; if (number % 2 == 0) { return "(" + create_string(number / 2) + ")*(1+1)"; } else { return "(" + create_string(number - 1) + ")+1"; } } int main() { ios_base::sync_with_stdio(0); int t, n; cin >> t; for (int q = 0; q < t; q++) { cin >> n; if (n == 1) { cout << "1\n"; } else { cout << create_string(n) << 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 31 32 | #include <iostream> using namespace std; string create_string(int number) { if (number == 2) return "1+1"; if (number % 2 == 0) { return "(" + create_string(number / 2) + ")*(1+1)"; } else { return "(" + create_string(number - 1) + ")+1"; } } int main() { ios_base::sync_with_stdio(0); int t, n; cin >> t; for (int q = 0; q < t; q++) { cin >> n; if (n == 1) { cout << "1\n"; } else { cout << create_string(n) << endl; } } return 0; } |