C++ log(n) time complexity easy code


#1

int Solution::isPower(int A) {

if(A<=0 || A==2)
{
    return 0;
}

if(A==1)
{
return 1;
}

for(int i=2;i<=sqrt(A);i++)
{
    if(A%i==0)
    {
        for(int j=1;j<=32;j++)
        {
            if(pow(i,j)==A) return 1;
        }
    }
}
return 0;

}


#2

j==2 ?
Although it passes but this is a slight inaccuracy as P>1.


#3

its not log(N), it is sqrt(N) * log(N)