// Solution to 2JED // Author: Michal Czuczman <michal.czuczman@gmail.com> // created on Tue Nov 22 19:05:37 CET 2016 #include <iostream> using namespace std; typedef unsigned int uint; typedef unsigned long long ull; string ones(int n, bool need_parens) { if(n == 1) { return "1"; } else if(n == 2) { if(need_parens) { return "(1+1)"; } else { return "1+1"; } } else if(n & 1) { if(need_parens) { return "(1+" + ones(n - 1, false) + ")"; } else { return "1+" + ones(n - 1, false); } } else { return "(1+1)*" + ones(n >> 1, true); } } void test() { int n; cin >> n; cout << ones(n, false) << '\n'; } int main() { ios::sync_with_stdio(false); int z; for (cin >> z; z; --z) test(); }
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 45 | // Solution to 2JED // Author: Michal Czuczman <michal.czuczman@gmail.com> // created on Tue Nov 22 19:05:37 CET 2016 #include <iostream> using namespace std; typedef unsigned int uint; typedef unsigned long long ull; string ones(int n, bool need_parens) { if(n == 1) { return "1"; } else if(n == 2) { if(need_parens) { return "(1+1)"; } else { return "1+1"; } } else if(n & 1) { if(need_parens) { return "(1+" + ones(n - 1, false) + ")"; } else { return "1+" + ones(n - 1, false); } } else { return "(1+1)*" + ones(n >> 1, true); } } void test() { int n; cin >> n; cout << ones(n, false) << '\n'; } int main() { ios::sync_with_stdio(false); int z; for (cin >> z; z; --z) test(); } |