快速幂
作者:互联网
#include<iostream>
using namespace std;
const int maxn = 1e5+5;
typedef long long ll;
ll fastpow(ll a , ll n){
if(n==1) return a;
ll temp = fastpow(a,n/2);
if(n%2==1) //如果n是奇数,n/2向下取整,则会使得a少乘一个次方
return temp*temp*a;
else
return temp*temp;
}
int main(){
ll a,n;
cin>>a>>n;
cout<<fastpow(a,n);
return 0;
}
标签:return,temp,int,ll,long,快速,fastpow 来源: https://www.cnblogs.com/ganl/p/16684162.html