#include <iostream> std::string jedExp(long &val) { std::string exp; while(val > 1 && val % 2 == 0) { exp += "(1+1)*"; val /= 2; } if(val > 1) { exp += "(1+"; val -= 1; exp += jedExp(val); exp += ")"; } else exp += "1"; return exp; } int main() { int t; long k; std::cin >> t; for(int i = 0; i < t; i++) { std::cin >> k; std::cout << jedExp(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 | #include <iostream> std::string jedExp(long &val) { std::string exp; while(val > 1 && val % 2 == 0) { exp += "(1+1)*"; val /= 2; } if(val > 1) { exp += "(1+"; val -= 1; exp += jedExp(val); exp += ")"; } else exp += "1"; return exp; } int main() { int t; long k; std::cin >> t; for(int i = 0; i < t; i++) { std::cin >> k; std::cout << jedExp(k) << std::endl; } return 0; } |