快速幂

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 #define mod 1003
 6 
 7 int quick_power(int a, int b)
 8 {
 9 if(a == 0) return 0;
10 int ret = 1;
11 while(b)
12 {
13 if(b & 1)
14 ret = ret * a % mod;
15 a = a * a % mod;
16 b /= 2;
17 }
18 return ret;
19 }
20 
21 int main()
22 {
23 int T;
24 scanf("%d", &T);
25 while(T--)
26 {
27 int m, n;
28 scanf("%d %d", &m, &n);
29 printf("%d\n", quick_power(m % mod, n));
30 }
31 }

 

posted @ 2015-01-09 18:54  zach96  阅读(126)  评论(0编辑  收藏  举报