Power of nine degrees OJ 1095 2

Source: Internet
Author: User

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

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.