#include<iostream>
using namespace std;
typedef long long LL;
#pragma warning(disable:4996)
int qni(int a, int k, int p) {
//返回a^k%p的结果
LL res = 1;
while (k) {
if(k&1) res = res * a % p;//如果k的末尾是1
k = k >> 1;
a = (LL)a * a % p;
}
return res;
}
int main() {
int n;
scanf("%d", &n);
while(n--) {
int a, k, p;
scanf("%d%d%d", &a, &k, &p);
printf("%d\n", qni(a, k, p));
}
}
AcWing875 快速幂
最新推荐文章于 2024-11-09 13:08:09 发布