No float, No double | Simple cpp solution


#1

Here is a Simple bruteforce code that works in O(sqrt(n)*log(n)) complexity.

Code

int Solution::isPower(int num) {
long long a,p;
if(num == 1)
{
return true;
}

else
{
    for(a = 2; a*a<= num;++a)
    {
        long long chkNum = a*a;
        for(long long p=2;chkNum<=num;++p)
        {
            if(chkNum == num)
                return true;
            else

                chkNum *=a;
        }
    }
    return false;
}

}