提交时间:2024-08-20 12:14:18

运行 ID: 168627

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