int Solution::isPower(int A) {
long double a,b;
// cout<<a;
if(A==1)
{
return 1;
}
for(float i=2;i<=A;i++)
{
b=1/i;
//cout<<i<<endl;
a=pow(A,b);
//cout<<a<<endl<<(int)a<<endl;
if((int)a == a)
{
return 1;
}
}
return 0;
}
Even when int(a) is equals to a ,it is not returning 1.The problem is because of using long double type number.But when i use float type then it does not work for large numbers.
Aucun commentaire:
Enregistrer un commentaire