D 人见人爱A^BmodC
计算A的B次幂对c取模(A^BmodC)并且1<=A,B,C<=32768.
输入三个整数A,B,C,输入文件每一行依次三个整数a,b,c用空格隔开
每行输出一个运算结果
Sample:
Input:
3 4 5
10 10 100
45 67 89
1 1 1
Output:
1
0
45
0
试题分析:
这是第四题,是一道快速幂的模板题,在我的博客里有快速幂的详细教程,我直接贴代码:
#include<stdio.h>
int pow_mod(int a,int b,int m)
{
int ans=1;
a=a%m;
while(b>0)
{
if(b%2==1)
ans=(ans*a)%m;
b=b/2;
a=a*a%m;
}
return ans;
}
int main()
{
int a,b,m,score;
while(scanf("%d%d%d",&a,&b,&m)!=EOF)
{
score=pow_mod(a,b,m);
printf("%d\n",score);
}
return 0;
}