快速幂就是小学奥数里的反复平方法
#include <iostream>
using namespace std;
typedef long long LL;
int qmi(int a, int b, int p) //快速幂模板,背就完了
{
int res = 1 % p;
while (b)
{
if (b & 1) res = (LL)res * a % p;
b >>= 1;
a = (LL)a * a % p; //a是一直在平方的
}
return res;
}
int main()
{
int a, b, p;
cin >> a >> b >> p;
cout << qmi(a, b, p) << endl;
return 0;
}
背就完了,硬气,孩子表示看不懂,那就背了