http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1046
分析:
快速幂 :http://blog.youkuaiyun.com/mm__1997/article/details/71794859
AC代码:
#include <stdio.h>
typedef long long LL;
LL mod;
LL Power(LL a,LL b){
LL temp=1;
while (b){
if(b%2)// 将b逐位转化为二进制 并判断该为是0还是1 0则不需要乘进去
temp=(temp*a)%mod;
b/=2; // 相当于将b的二进制右移一位
a=a*a%mod;// 求a的几次方
}
return temp;
}
int main (){
LL a,b;
scanf ("%lld%lld%lld",&a,&b,&mod);
printf ("%lld\n",Power(a,b));
return 0;
}

被折叠的 条评论
为什么被折叠?



