Why this code is failing?


#1

int Solution::isPower(int A) {
long long n = sqrt(A);

if(A==1)
    return true;
if(A==2)
    return false;

for(int i=2;i<n+1;i++){
    double a=log(A),b=log(i);
    double t = a/b;
    // cout << int(t) << " " << t <<endl;
    if(int(t) == t){
        // cout << t << endl;
        return true;
    }
}
return false;

}


#2

(int)t is equivalent to floor(t), what you should be using instead is round(t)

(int)1.9999999 = 1
round(1.999999) = 2