#include<cstdio>
typedef __int64 LL;
int a, k, mod;
int pow_mod(int a, int k, int mod)//非递归
{
int res = 1;
while(k)
{
if(k & 1)
res = ((LL)res * (LL)a) % mod;
k >>= 1;
a = ((LL)a * (LL)a) % mod;
}
return res;
}
int main()
{
while(~scanf("%d%d%d", &a, &k, &mod))//int范围够吗?
printf("%d\n", pow_mod(a, k, mod));
return 0;
}
FAFU OJ 求幂模
原创
©著作权归作者所有:来自51CTO博客作者兔云程序的原创作品,请联系作者获取转载授权,否则将追究法律责任
Description:
求c^e÷n的余数(c的e次方除以n的模)。
Input:
输入有一行三个整数c,e,n。
Output:
输出只有一个整数,即所求结果。
Sample Input:
2 10 100
Sample Output:
24
Hint:
0≤c≤1000000000,0≤e≤1000000000,1≤n≤10000, 时间限制≤1秒
Source:
上一篇:FAFU OJ 18岁的生日
下一篇:FAFU OJ 子串
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
接口幂等方案
接口幂等方案
ide 幂等 Express