[Daily learning] [Search/recursion] The power of codevs2802 and codevs2802

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.