链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=102
用二分求幂:注意要用长整形
#include <stdio.h> int main() { long long power(int a,int b,long long c); int n; int a,b,c; scanf("%d",&n); while(n--) { scanf("%d%d%d",&a,&b,&c); printf("%lld\n",power(a,b,c)); } return 0; } long long power(int a,int b,long long c) //a^b%c { if(b==0) return 1; if(b==1) return a%c; long long ans=power(a,b/2,c); ans=(ans%c*ans%c)%c; if(b%2) ans*=a; return ans%c; }
天下武功,唯快不破