#include <iostream> #include <algorithm> #include <vector> #include <set> /** 19 19 % 2 = 1 9 % 2 = 1 4 % 2 = 0 2 % 2 = 0 (1 + (1 + 1) * (1 + (1 + 1) * ((1 + 1) * (1 + 1)))) **/ int main() { int test = 0; std::cin >> test; std::string out; for (int i = 0; i < test; i++) { std::string oper = ""; std::string end_bracket = ""; int val = 0; std::cin >> val; int init = val; int count = 0; while (val != 1) { int mod = val % 2; if (mod == 1) { count++; oper += "1+"; val -= 1; } val /= 2; if (val != 1) { oper += "(1+1)"; count += 2; oper += "*("; end_bracket += ")"; } else { oper += "1+1"; count += 2; } } oper += end_bracket; if (count < 101) { if (init == 1) { out += "1\n"; } else { out += oper + "\n"; } } else { out += "NIE\n"; } } std::cout << out; /**for (int i = 99990; i < 100000; i += 2) { std::string oper = ""; std::string end_bracket = ""; int count = 0; int val = i; while (val != 1) { int mod = val % 2; if (mod == 1) { count++; oper += "1+"; val -= 1; } oper += "(1+1)"; count += 2; val /= 2; if (val != 1) { oper += "*("; end_bracket += ")"; } } oper += end_bracket; //std::cout << oper << " : " << count << "\n"; if (count < 101) std::cout << oper << "\n"; else std::cout << "NIE\n"; **/ /**if (i % 10000000 == 0) { std::cout << i << "\n"; } }**/ }
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> #include <algorithm> #include <vector> #include <set> /** 19 19 % 2 = 1 9 % 2 = 1 4 % 2 = 0 2 % 2 = 0 (1 + (1 + 1) * (1 + (1 + 1) * ((1 + 1) * (1 + 1)))) **/ int main() { int test = 0; std::cin >> test; std::string out; for (int i = 0; i < test; i++) { std::string oper = ""; std::string end_bracket = ""; int val = 0; std::cin >> val; int init = val; int count = 0; while (val != 1) { int mod = val % 2; if (mod == 1) { count++; oper += "1+"; val -= 1; } val /= 2; if (val != 1) { oper += "(1+1)"; count += 2; oper += "*("; end_bracket += ")"; } else { oper += "1+1"; count += 2; } } oper += end_bracket; if (count < 101) { if (init == 1) { out += "1\n"; } else { out += oper + "\n"; } } else { out += "NIE\n"; } } std::cout << out; /**for (int i = 99990; i < 100000; i += 2) { std::string oper = ""; std::string end_bracket = ""; int count = 0; int val = i; while (val != 1) { int mod = val % 2; if (mod == 1) { count++; oper += "1+"; val -= 1; } oper += "(1+1)"; count += 2; val /= 2; if (val != 1) { oper += "*("; end_bracket += ")"; } } oper += end_bracket; //std::cout << oper << " : " << count << "\n"; if (count < 101) std::cout << oper << "\n"; else std::cout << "NIE\n"; **/ /**if (i % 10000000 == 0) { std::cout << i << "\n"; } }**/ } |