#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int a, b, p;
cin >> a >> b >> p;
int res = 1 % p;
while (b)
{
if (b & 1) res = (long long)res * a % p;//这里的%p纯粹是为了防止数据溢出;
a = (long long)a * a % p;//利用二进制和(a*b)%p=(a%p*b%p)%p
b >>= 1;
}
cout << res << endl;
return 0;
}
ACwing 89. a^b
最新推荐文章于 2024-08-23 12:25:05 发布