Log does the job!


#1

int Solution::isPower(int A) {
if(A==0)
return false;
if(A==1)
return true;
set factor;
for(int i=2;i*i<=A;i++)
{
if(A%i==0)
{
factor.insert(i);
factor.insert(A/i);
}
}
set::iterator itr;
for(itr=factor.begin();itr!=factor.end();itr++)
{
int base = *itr;
float l = log10(A)/log10(base);
if(int(l)>=1 && int(l)==l)
return true;
}
return false;
}