Files
workspace/cpp/algo/fastpow.cpp
2026-01-31 14:38:00 +08:00

20 lines
368 B
C++

#include <iostream>
using namespace std;
double fastpow(double x, int a){
if(a == 0) return 1.0;
if(a < 0) return 1.0 / fastpow(x, -a);
double ans = fastpow(x, a/2);
ans *= ans;
if(a % 2 != 0) ans *= x;
return ans;
}
int main(){
int a; double b;
cin >> b >> a;
//cout << b << a;
cout << fastpow(b, a) << endl;
return 0;
}