#P1010. Recursive Binary Power Representation
Recursive Binary Power Representation
Recursive Binary Power Representation
Any positive integer can be expressed as a sum of powers of 2. For example, \(137=2^7+2^3+2^0\). We adopt a convention where the exponent is shown in parentheses. That is, \(a^b\) is written as \(a(b)\). Thus, \(137\) is written as \(2(7)+2(3)+2(0)\).
Furthermore, the exponents themselves can be recursively represented in the same way. For instance, note that \(7=2^2+2^1+2^0\) (here \(2^1\) is denoted simply by 2) and \(3=2^1+2^0\). Therefore, the final representation of \(137\) becomes:
[ 137=2(2(2)+2+2(0))+2(2+2(0))+2(0). ]
Similarly, for \(1315=2^{10}+2^{8}+2^{5}+2^1+2^0\), the final representation is:
[ 1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0). ]
</p>Task: Given a positive integer \(N\), express it in this recursive format. Formally, represent \(N\) by writing it in its binary expansion \(N=\sum 2^{k}\). For each term:
- If \(k=0\), output
2(0)
. - If \(k=1\), output
2
. - If \(k>1\), output
2( [representation of k] )
, where the representation of \(k\) is computed recursively using the same rules.
Join the terms for all bits in descending order of \(k\) using a plus sign (+).
inputFormat
The input consists of a single positive integer \(N\) (1 \(\leq N \leq\) 109).
outputFormat
Output the recursive representation of \(N\) as described above.
sample
137
2(2(2)+2+2(0))+2(2+2(0))+2(0)