fastpower
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 int ans,n=1012,k; 6 int fastpower(int x,int y){//x^y%n 7 ans=1; 8 k=x%n; 9 while(y){ 10 if(y%2)//y是奇数 11 ans=(ans*k)%n; 12 k=(k*k)%n; 13 y=y/2; 14 } 15 return ans; 16 } 17 int main(){ 18 int a,b,c; 19 cin>>a; 20 for(int i=0;i<a;i++){ 21 scanf("%d%d",&b,&c); 22 printf("%d\n",fastpower(b,c)); 23 } 24 return 0; 25 }