简单题。解法可参考NYOJ 88
附ac代码:
#include <stdio.h>
long long f(int a, int b, int c){
if(a == 1) return 1 % c;
if(b == 1) return a % c;
long long s = f(a, b / 2, c);
s = s * s % c;
if(b & 1) return s * a % c;
return s;
}
int main(){
int a, b, c, t;
scanf("%d", &t);
while(t-- && scanf("%d%d%d", &a, &b, &c))
printf("%lld\n", f(a, b, c));
return 0;
}