提交时间:2024-08-20 12:15:53

运行 ID: 168630

#include <bits/stdc++.h> using namespace std; int a[20] = {1}; void fun(int n) { int f = 0; while (n >= a[f]) f++; f--; if (f == 1) cout << 2; else { if (f == 0) cout << "2(0)"; else { cout << "2("; fun(f); cout << ")"; } } n -= a[f]; if (n != 0) { cout << "+"; fun(n); } } int main() { int n; cin >> n; for (int i = 1; i < 17; i++) a[i] = a[i - 1] * 2; fun(n); return 0; }