Files
python/GESP/Level5/GESP202503/KMS.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

20 lines
603 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
// 快速幂
int qmi(int a, int b) {
int r = 1; // 初始化结果为1
a %= p; // 先取模防止溢出
while (b) { // 当指数不为0时循环
if (b & 1) // 如果当前二进制位是1
r = (1LL * r * a) % p; // 累乘当前基数
a = (1LL * a * a) % p; // 基数平方
b >>= 1; // 右移一位(相当于除以2)
}
return r;
}
int main() {
// (10)2=1010
cout << qmi(2, 10) << endl;
return 0;
}