您的位置:首页 > 其它

HDOJ 2035 人见人爱A^B-----二分快速求幂

2015-07-20 21:28 323 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2035

//二分快速求幂

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<ctype.h>

int main()

{

int a,b;

int s;

while(scanf("%d%d",&a,&b),a+b)

{

int cmp(int a,int b);

s=cmp(a,b);

printf("%d\n",s);

}

return 0;

}

int cmp(int a,int b)

{

int s=1;

while(b)

{

a%=1000;//取模

if(b&1)

{

s*=a;

s%=1000;

}

b>>=1;

a*=a;

}

return s;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: