#include<iostream>
#include<cstdio>
using namespace std;
int qpow(int base, int n){
int ans = 1;
while(n){
if(n&1) ans*=base;
base = base * base;
n/=2;
}
return ans;
}
int main(){
cout << qpow(2,1) << endl;
cout << qpow(2,2) << endl;
cout << qpow(2,10) << endl;
return 0;
}
【快速幂】O(logn)时间复杂度
猜你喜欢
转载自blog.csdn.net/abc1235454/article/details/88766541
今日推荐
周排行