double powPos(double x, long long n) {
if(n == 0)return 1;
if(n == 1)return x;
double a = powPos(x,n/2);
return (a*a*powPos(x, n%2));
}
double pow(double x, int n) {
long long ln = (long long)n;
double res = powPos(x,abs(ln));
if(n<0)res = (double)1.0/res;
return res;
}
No comments:
Post a Comment