Why code is not working?


#1

int Solution::isPower(int A) {

if(A==1)
    return 1;
for(int i=2;i*i<=A;i++){
    float m=(float)log(A)/(float)log(i);
    if(ceil(m)==floor(m))
        return 1;
        
}
return 0;

}int Solution::isPower(int A) {

if(A==1)
    return 1;
for(int i=2;i*i<=A;i++){
    float m=(float)log(A)/(float)log(i);
    if(ceil(m)==floor(m))
        return 1;
        
}
return 0;

}


#2

This will not work for the number: 536870912 i.e. 2^29 as the value in m will be rounded after a certain precision. so m will be of format xx.000000000…yyy for which ceil and floor will be different.
You can fix this by verifying if pow(m,i) == A
or for this particular question you can even use if(m-(int)m) <= 0.0000001) return 1;