http://acm.hdu.edu.cn/showproblem.php?pid=1420
int main()
{
int a,b,c,n;
__int64 sum;
scanf("%d",&n);
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
sum=1;
while(b--)
{
sum=sum*a%c;
}
printf("%I64d\n",sum);
}
}
http://acm.hdu.edu.cn/showproblem.php?pid=1420