Power of Topic 1095:2
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:772
Resolution:525
-
topic Description:
-
every positive number can be presented by the exponential form. For example, 137 = 2^7 + 2^3 + 2^0.
let ' s Present a^b by the form a (b). Then 137 are presented by 2 (7) +2 (3) +2 (0). Since 7 = 2^2 + 2 + 2^0 and 3 = 2 + 2^0, 137 is the finally presented by 2 (2) 2 +2 (+2)) 0 (+ +2) 0 (+2).
& nbsp; Given A positive number N,your task is to present n with the exponential Form which only contains t He digits 0 and 2.
-
Input:
-
For each case, the input file contains a positive integer n (n<=20000).
-
Output:
-
For each case, you should output the exponential form of n an A. Note That,there should is no additional white spaces in the line.
-
Sample input:
-
1315
-
Sample output:
-
2 (2 (+ + (0)) +2) +2 (2 (+ + (0))) +2 (2 (2) +2 (0)) +2+2 (0)
#include <stdio.h> #include <math.h>void solve (int n) { int cnt=0; while (POW (2,cnt) <=n) cnt++; cnt--; if (cnt==0) printf ("2 (0)"); else if (cnt==1) printf ("2"); else { printf ("2 ("); Solve (CNT); printf (")"); } int Num_r=n-pow (2,cnt); if (Num_r) { printf ("+"); Solve (Num_r); }} int main () { int n; while (~SCANF ("%d", &n)) { solve (n); printf ("\ n"); } return 0;} /************************************************************** problem:1095 user:kirchhoff Language:c result:accepted time:0 ms memory:1004 kb********************************************** ******************/
Power of nine degrees OJ 1095 2