Elegant C++ Solution


int Solution::isPower(int A) {
return 1;
for(int i=2;i<=sqrt(A);i++)
float a=log(A)/log(i);
return 1;
return 0;


Why doesn’t it work with double instead of float?


@ devanshanandtiwari_5 Did you figure it out?


It might be because if you use (double==int) in IF condition it will always return false but thats not the case if you use (float==int) =>(a==floor(a)) but if you write like this
double a=log(A)/logi;
int b=(int) a;
return 1;
This will work.Again if you use if(a==b) this wont work becuase its (double==int).
Hope this helps!!!