P1226 【模板】快速幂
url: https://www.luogu.com.cn/problem/P1226
tag:
快速幂,模板
代码:
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
LL a, k, p;
cin >> a >> k >> p;
LL kk = k;
LL aa = a;
LL res = 1;
while (k)
{
if (k & 1) res = (LL)res * a % p;
k >>= 1;
a = (LL)a * a % p;
}
printf("%lld^%lld mod %lld=%lld",aa, kk, p, res);
return 0;
}
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »