You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
686 B

## $P1226$ 【模板】快速幂||取余运算
[题目传送门](https://www.luogu.com.cn/problem/P1226)
### 一、经验总结
* 因为在计算快速幂过程中,会进行乘法运算,可能会爆$INT$,一般采用$LL$对所有参数进行定义
### 二、实现代码
```c++
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a, b, p;
LL qmi(LL x, LL y, LL p) {
LL res = 1;
while (y) {
if (y & 1) res = res * x % p;
y >>= 1;
x = x * x % p;
}
return res;
}
int main() {
scanf("%d %d %d", &a, &b, &p);
printf("%d^%d mod %d=%lld\n", a, b, p, qmi(a, b, p));
return 0;
}
```