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;}