HDU 1420 Prepared for New Acmer【快速幂】
Input
输入数据首先包含一个正整数N,表示测试实例的个数,然后是N行数据,每行包括三个正整数A,B,C。
Output
对每个测试实例请输出计算后的结果,每个实例的输出占一行。
Sample Input
3 2 3 4 3 3 5 4 4 6
Sample Output
0 2 4
code:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> int mod; int fu(long long a,long long b) { long long ans=1,m=a; while(b) { if(b&1) ans=(ans*m)%mod; b>>=1; m=(m*m)%mod; } return ans; } int main() { int res,a,b,c; int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&a,&b,&c); mod=c; printf("%d\n",fu(a,b)); } return 0; }