D - A^B Mod C
给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)
Output
输出计算结果
Sample Input
3 5 8
Sample Output
3
快速幂模板题
#include<stdio.h>
typedef long long ll;
ll mod(ll a,ll b,ll c){
ll res=1;
while(b){
if(b&1) res=res*a%c;
a=a*a%c;
b>>=1;
}
return res;
}
int main(){
ll a, b,c,t;
scanf("%lld %lld %lld",&a,&b,&c);
t = mod(a,b,c);
printf("%lld\n",t);
return 0;
}