提交时间:2024-08-20 12:19:43
运行 ID: 168631
#include <bits/stdc++.h> using namespace std; int n, a[15]; void fun(int t) { if (t / 2 == 1) { cout << "2"; if (t - 2) { cout << "+"; fun(t - 2); } } else { cout << "2("; int num = 0; for (int i = 0; i <= 15; i++) if (a[i] > t) { num = i - 1; break; } if (num > 2) { fun(num); cout << ")"; } else cout << num << ")"; if (t - a[num]) { cout << "+"; fun(t - a[num]); } } } int main() { cin >> n; a[0] = 1; for (int i = 1; i <= 15; i++) a[i] = a[i - 1] * 2; fun(n); return 0; }