HDOJ2035 人见人爱A^B 二分法

原题链接


//二分法2014-3-11 19:10:15
#include <stdio.h>

int f(int a, int b){
	if(b == 1) return a;	
	int s = f(a, b / 2);
	if(b & 1) return s * s * a % 1000;
	else return s * s % 1000;
}

int main(){
	int a, b;
	while(scanf("%d%d", &a, &b), a || b){
		a %= 1000;
		printf("%d\n", f(a, b));
	}
	return 0;
}


posted on 2014-03-11 19:16  长木Qiu  阅读(150)  评论(0编辑  收藏  举报