提交时间:2024-08-20 09:42:19
运行 ID: 168327
#include <bits/stdc++.h> using namespace std; int n, a[17]; int f (int x) { if (x == 0) { cout << "0"; return 0; } if (x == 2) { cout << "2"; return 0; } while (1) { int i; for (i = 16; a[i] > x; i--); if (a[i] != 2) { cout << "2("; f(i); cout << ")"; } else { cout << "2"; } if (x - a[i]) { cout << "+"; x -= a[i]; } else { return 0; } } } int main () { a[0] = 1; for (int i = 1; i <= 16; i++) { a[i] = a[i - 1] * 2; } cin >> n; f(n); return 0; }