class Solution {
public:
double myPow(double x, int n) {
double ans=1.0;
if(x==0)return 0.0;
long b=n;
if(b<0){
x=1/x;
b=-b;
}
while(b){
if(b&1)ans*=x;
x*=x;
b>>=1;
}
return ans;
}
};