提交时间:2024-08-20 15:07:04
运行 ID: 168970
#include<iostream> using namespace std; void f(int n) { if (n == 0) cout << 0; else if (n == 1) cout << "2(0)"; else if (n == 2) cout << "2"; else { int t = n, cnt = 0; while (t) { t >>= 1; cnt++; } bool flag = 1; for (int i = cnt - 1; i >= 0; i--) { if ((n >> i) & 1) { if (flag) flag = 0; else cout << "+"; if (i == 1) cout << 2; else cout << "2(", f(i), cout<<")"; } } } } int main() { int n; cin >> n; f(n); return 0; }