1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <bits/stdc++.h>
using namespace std;
void f(int x) { for (int i = 30; i >= 0; --i) { if (x & (1 << i)) { if (i == 0) cout << "2(0)"; else if (i == 1) cout << "2"; else cout << "2(", f(i), cout << ")"; x ^= 1 << i; if (x) cout << "+"; } } }
int main() { int n; cin >> n; f(n); return 0; }
|