3 2 3 4 3 3 5 4 4 6
0 2 4
#include<stdio.h> 
int main()
{
	int i,n,a,b,c;
	scanf("%d",&n);
	while(n--)
	{
		__int64 temp,sum;
		scanf("%d%d%d",&a,&b,&c);
		sum=a%c;
		temp=1;
		while(b>1)//因为起初的时候,已经是a%c了所以已经是一次方了 
		{
			if(b&1)//奇数的话,单独拉出来 
			{
				temp*=sum;//temp用来存储奇数情况下的所有的乘积 
				temp%=c;
				b--;//单独拉出来,次数减一 
			}
			else
			{
				sum*=sum;//降幂法 
				sum%=c;
				b/=2;//因为是变化后乘方,所以次方数减半 
			}
		}
		printf("%I64d\n",sum*temp%c);
	}
	return 0;
}hdu 1420(Prepared for New Acmer)(中国剩余定理)(降幂法)
原文地址:http://blog.csdn.net/ice_alone/article/details/40508779