标签:
1 int f1(int a,int b) 2 { 3 int t=1; 4 while(b) 5 { 6 if(b % 2 != 0) 7 { 8 t*=a; 9 b--; 10 } 11 a*=a; 12 b/=2; 13 } 14 return t; 15 }
1 int f2(int a,int b) 2 { 3 int t=1; 4 while(b) 5 { 6 if(b % 2 != 0) 7 { 8 t=(t*a)%x; //x控制要求的位数 9 b--; 10 } 11 a=(a*a)%x; 12 b/=2; 13 } 14 return t; 15 }
1 #include<cstdio> 2 int f(int a,int b) 3 { 4 int t=1; 5 while(b) 6 { 7 if(b%2!=0) 8 { 9 t=(t*a)%1000; 10 b--; 11 } 12 a=a*a%1000; 13 b/=2; 14 } 15 return t; 16 } 17 int main() 18 { 19 int a,b; 20 while(scanf("%d %d",&a,&b)&&a&&b) 21 { 22 printf("%d\n",f(a,b)); 23 } 24 }
标签:
原文地址:http://www.cnblogs.com/yexiaozi/p/5697995.html