Title Description Description Any positive integer can be expressed in 2 notation, for example: 137 of the 2 binary is represented as 10001001.
The 2 notation is written in the form of the sum of the power of 2, and the second power is preceded by the following expression: 137=2^7+2^3+2^0
The Covenant power is now represented by parentheses, which means that a^b is represented as a (b)
At this point, 137 can be represented as: 2 (7) +2 (3) +2 (0)
Further: 7=2^2+2+2^0 (2^1 with 2)
3=2+2^0
So the last 137 can be represented as: 2 (2 (2) +2+2 (0)) +2 (+ 0) +2 (0)
Another example: 1315=2^10+2^8+2^5+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/output format input/output Input format positive integer (1<=n<=20000) output format conforms to the 0,2 representation of the contract n (cannot have spaces in the representation)
sample Test point # #Sample input 137 Sample Output 2 (2 (2) +2+2 (0)) +2 (+ 0) +2 (0)
sample Test Point # #Sample input 1315 Sample output 2 (2 (+ +2 (0)) +2) 2 (0 (+2) 2 (2)) +2+2 (+2)
Tips:
Recursive implementation will be relatively simple, can be recursive side of the output code as follows:
1#include <stdio.h>2 inty=0, oo;3 intFun2 (intYintFloor )4 {5 intT;6 if(y==0)7 {8 return 0;9 }Ten Else One { At=y%2; -Fun2 (y/2, floor+1); - if(t==1) the { - if(floor==1) - { - if(y/2==0)//Highest bit + { -printf"2"); + } A Else at { -printf"+2"); - } - } - Else - { in if(y/2==0)//Highest bit - { to if(floor==0) + { -printf"2 (0)"); the } * Else $ {Panax Notoginsengprintf"2 ("); -FUN2 (Floor,0); theprintf")"); + } A } the Else + { - if(floor==0) $ { $printf"+2 (0)"); - } - Else the { -printf"+2 (");WuyiFUN2 (Floor,0); theprintf")"); - } Wu } - About } $ - } - } - return 0; A } + intMain () the { - intN; $scanf"%d",&n); theFUN2 (N,0); theprintf"\ n"); the return 0; the}
Rokua-recurses representation of 2-process function and recursion