TYVJ 1118 a^b 解题报告

  暴搜就行,还有一个方法,是logn的算法的,等下看a^b2的代码吧,上暴搜的代码:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	int i;
	int a, b;
	int s = 1;
	scanf("%d%d", &a, &b);
	for(i = 1; i <= b; i++){
		s *= a;
		s %= 1012;
	}
	printf("%d\n", s);
	return 0;
}

  

posted @ 2011-08-07 17:34  zqynux  阅读(123)  评论(0编辑  收藏  举报