码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 2035

时间:2016-02-28 22:40:02      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

Ps:查了下快速幂,顺便在这用下....

   积的求余等于两个数的求余的积再求余...

代码:

#include "stdio.h"
int mod(int a,int b);
int main(){
 int a,b,n;
 while(~scanf("%d%d",&a,&b) &&(a||b) ){
  printf("%d\n",mod(a,b)); 
 }
 return 0;
}
int mod(int a,int b){
 int ans=1;
 a=a%1000;
 while(b>0){
  if(b%2==1) ans=(ans*a)%1000;
  b=b/2;
  a=(a*a)%1000; 
 }
 return ans;
}

hdu 2035

标签:

原文地址:http://www.cnblogs.com/sureli/p/5225721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!