'commit'
This commit is contained in:
31
TangDou/AcWing/Math/P1226.md
Normal file
31
TangDou/AcWing/Math/P1226.md
Normal file
@@ -0,0 +1,31 @@
|
||||
## $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;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user