O(sqrt(N)) solution c++


#1

int Solution::isPower(int A) {
//cout << A;
int limit = sqrt(A);
for(int i = 1;i<=limit;i++){
for(int j = 2;j<=31;j++){
int sum = pow(i,j);
if(sum == A) { return 1;}
}
}
return 0;

}


#2

can you explain the logic behind j<=31


#3

observe carefully we have total bits of 32 so max number doesn’t exceed num^31.


#4

this is how i did


#5

in integer i guess number should not exceed 2^31 not num^31 ,correct me if im missing something


#6

Explain the logic behind j<=31