Zju2124 perfect PTH powers-pow Function

Source: Internet
Author: User

Description:

Returns an integer x in the int range, and returns the maximum P value of X = B ^ p.

Analysis:

Because X is within the int range, the value of P is 1 to 31. Enumerate,Use the POW function to open X and then verify it.

Wrong several times ...... The reason is:Data may be 2 ^ 31And there areNegativeBut the question clearly says "the value of X will have magn=at least 2 and be within the range of A (32-bit) int in C, C ++, and Java ", depressed ......

You cannot trust questions too much or your English skills too much ......

/*ZJU2124 Perfect Pth Powers*/#include 
 
  #include 
  
   #define int64 long long#define I64d "%lld"int64 POW(int b,int p){    int i;    int64 s=1;    for(i=0;i< p;i++) s*=b;    return s;}int main(){    int64 x,n;    int i,y;        while(scanf(I64d,&n),n){        x=n>0?n:-n;        for(i=32;i>=2;i--){            y=(int)(pow((double)x,1.0/i)+0.5);            if(POW(y,i)==x){                if(n<0 && i%2==0) continue;                else printf("%d/n",i);                break;            }        }        if(i==1) printf("1/n");    }        return 0;}
  
 

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.