28 lines
484 B
C++
28 lines
484 B
C++
|
|
#include <iostream>
|
|||
|
|
using namespace std;
|
|||
|
|
typedef long long LL;
|
|||
|
|
const LL mod = 1e9 + 7;
|
|||
|
|
/*
|
|||
|
|
测试用例:
|
|||
|
|
5 8
|
|||
|
|
|
|||
|
|
结果:
|
|||
|
|
390625
|
|||
|
|
*/
|
|||
|
|
//快速幂
|
|||
|
|
LL ksm(LL a, LL b) {
|
|||
|
|
LL ans = 1;
|
|||
|
|
a %= mod;
|
|||
|
|
while (b) {
|
|||
|
|
if (b & 1) ans = (ans * a) % mod;
|
|||
|
|
b >>= 1; //位运算,右移1位,相当于除以2
|
|||
|
|
a = (a * a) % mod;
|
|||
|
|
}
|
|||
|
|
return ans;
|
|||
|
|
}
|
|||
|
|
int main() {
|
|||
|
|
LL a, b;
|
|||
|
|
cin >> a >> b;
|
|||
|
|
printf("%lld\n", ksm(a, b));
|
|||
|
|
return 0;
|
|||
|
|
}
|