//土尔逊Torson 编写于2023/06/02 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> using namespace std; //次方计算 base 的 n 次方 int MyPow(int base, int n) { int result = 1; for (int i = 0; i < n; ++i) { result *= base; } return result; } // 计算把N分解成2的i幂次方数之和的系数集合,例如9=2^3+2^0,返回值就是3和0 vector<int> ToArray(int n) { vector<int> b; int i = 0; while (n > 0) { while (n - MyPow(2, i) > 0) { i++; } if (n < MyPow(2, i)) { i--; } n = n - MyPow(2, i); b.push_back(i); i = 0; } return b; } //构建答案 string Build(int n) { vector<int> a; a = ToArray(n); int size = a.size(); string str = ""; for (int i = 0; i < size; ++i) { if (a[i] == 1) { str += "2"; } else if (a[i] == 0) { str += "2(0)"; } else { str += "2(" + Build(a[i]) + ")"; } if (i != size - 1) { str += "+"; } } return str; } int main() { int n; while (scanf("%d", &n) != EOF) { printf("%s", Build(n).c_str()); } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")