NYOJ 102 次方求模

原题链接

简单题。解法可参考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;
}


posted on 2014-02-12 15:46  长木Qiu  阅读(114)  评论(0编辑  收藏  举报