1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 using namespace std ;13 #ifdef DeBUG14 #define bug assert15 #else16 #define bug //17 #endif18 int pow3(int a, int b)19 {20 int r = 1, base = a;21 while(b != 0)22 {23 if(b & 1)24 r =(r* base)%100;25 base =(base* base)%100;26 b >>= 1;27 }28 return r;29 }30 31 int main()32 {33 #ifdef DeBUG34 freopen("C:\\Users\\Sky\\Desktop\\1.in","r",stdin);35 #endif36 37 int n;38 int i,j,k;39 int t;40 int m;41 int sum;42 scanf("%d",&t);43 while(t--)44 {45 sum=0;46 int now=0;47 scanf("%d%d",&n,&m);48 for(i=1;i<=n;i++)49 {50 sum=(sum+pow3(i,m))%100;51 }52 if(sum<10)53 printf("0%d\n",sum);54 else55 printf("%d\n",sum);56 }57 return 0;58 }
位操作版
int pow3(int a, int b)
{ int r = 1, base = a; while(b != 0) { if(b & 1) r *= base; base *= base; b >>= 1; } return r;}
int pow2(int a, int b)
{ int r = 1, base = a; while(b != 0) { if(b % 2) r *= base; base *= base; b /= 2; } return r;}