Welcome to the Csdn-markdown Editor

Source: Internet
Author: User

Problem description
Any positive integer can be represented by a power of 2. For example:
137=27+23+20
At the same time, the square is indicated by parentheses, that is, AB can be expressed as a (b).
The 137 can be expressed as:
2 (7) +2 (3) +2 (0)
Further: 7 = 22+2+20 (21 denoted by 2)
3=2+20
So the last 137 can be expressed as:
2 (2 (2) +2+2 (0)) +2 (+ (0)) +2 (0)
Another example:
1315=210 +28 +25 +2+1
So the last 1315 can be expressed as:
2 (2 (+ + (0)) +2) +2 (2 (+ + (0))) +2 (2 (2) +2 (0)) +2+2 (0)

Input format
The input contains a positive integer N (n<=20000), which is an integer that requires decomposition.

Output format
The program output contains a line of string that is represented by the 0,2 of the conforming n (cannot have spaces in the representation)

Import java.io.*; Public classMain { Public Static void Main(string[] args) throws Exception {BufferedReader BF =NewBufferedReader (NewInputStreamReader (System.inch));intA = Integer.parseint (Bf.readline ());if(a>=1&&a<3) {System. out. println ("2 ("+ (A-1)+")"); }Else{System. out. println (Fun (a)); }    } Public StaticString Fun(intNUM) {inttemp = num;Charc []=New Char[]{' 0 ',' 1 '};CharC1 []=New Char[1024x768];intA =1024x768; String s="";if(num>=0&& num<=2){returnnum+""; }Else{ Do{C1[--a] = c [temp&1]; Temp=temp>>1; } while(temp!=0); String S1 =NewString (C1,a,1024x768-a);intI=0; for(i=0; I<s1.length (); i++) {if((S1.charat (i)-' 0 ')==1) {s+="2 ("+fun (S1.length ()-1-I.) +")+"; }} s= S.replaceall ("2\\ (1\\)","2");returnS.substring (0, S.length ()-1); }    }}

Welcome to the Csdn-markdown Editor

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.