[Daily learning] [Search/recursion] The power of codevs2802 and codevs2802
For more information, see [All rights reserved for ametake] http://blog.csdn.net/ametake
Description
Description
Any positive integer can be expressed by the power of 2.
Example: 137 = 2 ^ 7 + 2 ^ 3 + 2 ^ 0
In addition, brackets are used to represent the power, that is, a ^ B can be expressed as a (B)
It can be seen that 137 can be expressed as: 2 (7) + 2 (3) + 2 (0)
Further: 7 = 2 ^ 2 + 2 + 2 ^ 0 (2 ^ 1 is expressed as 2)
3 = 2 + 2 ^ 0
So the last 137 can be expressed as: 2 (2 (2) + 2 + 2 (0) + 2 (2 + 2 (0) + 2 (0)
Another example: 1315 = 2 ^ 10 + 2 ^ 8 + 2 ^ 5 + 2 + 1
So 1315 can be expressed as: 2 (2 (2 + 2 (0) + 2) + 2 (2 + 2 (0 ))) + 2 (2 (2) + 2 (0) + 2 + 2 (0)
Input description
Input Description
Positive integer n
Output description
Output Description
0, 2 of the n that meets the conventions (there cannot be spaces in the representation)
Sample Input
Sample Input
[Example 1]
137
[Example 2]
1315
Sample output
Sample Output
[Output Example 1]
2 (2 (2) + 2 + 2 (0) + 2 (2 + 2 (0) + 2 (0)
[Output Example 2]
2 (2 (2 + 2 (0) + 2) + 2 (2 (2 + 2 (0) + 2 (2 (2) + 2 (0 )) + 2 + 2 (0)
Data range and prompt
Data Size & Hint
Index with n as 2 <= 1100586419200
The typical recursive question has not been searched for a long time. I will not write it. Thanks for the explicit margin ~
Read the Code directly.
The key is to output left parentheses first, recursively, and output the classic pattern of right parentheses.
There are other ways Leo's lowbit = learn slowly
Note that we need to use long to vomit 4.9.9.2. the compiler of a drama and codevs's strange Compilation Principle =
Code on
-- Old rewards are easy to use, so it becomes a travel event
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.