class Solution { public: double pow(double x, int n) { double a=1; if(n==0)return 1; if(x==1)return 1; if(x==-1) { if(n&1)return -1; else return 1; } int absn=abs(n); a=power(x,absn); if(n<0) { a=1/a; } return a; } double power(double x,int n) { double result=1; if(n==1)return x; if(n&1) { result*=x; n=n-1; } double temp=power(x,n>>1); result=result*temp*temp; return result; } };