C++ O(sqrt(n)) Solution


#1
bool isInteger(float n)
{
    return floor(n)==ceil(n);
}

int Solution::isPower(int n)
{
    int ans=(n==1)?1:0;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            if(isInteger(1.0*log(n/i)/log(i)))
            {
                ans=1;
                break;
            }
        }
    }
    return ans;
}


#2

relevance of log(n/i)? is it reducing complexity??