Simple Solution Approach dividing no


#1

int Solution::isPower(int A) {
if(A==1) return 1;
if(A<4)
return 0;
for(int i=2;i<=sqrt(A);i++)
{
if(A%i==0)
{
//cout<<i<<"\n";
//check for further powers
int temp =A,rem=0,n=1;
while(temp>1 && temp%i==0)
{
// rem=temp%i;
temp/=i;
n++;
//cout<<temp<<" r: “<<rem<<” “;
}
//cout<<”\n";
if(temp==1)
{
//cout<<" power “<<i<<” ^ “<<n<<”\n";
return 1;
}
}
}
return 0;
}