杭电 1097

来源:互联网 发布:数据库遍历.zip 编辑:程序博客网 时间:2024/06/04 23:28

快速取幂:

附上地址

http://baike.baidu.com/view/4533005.htm?fr=aladdin

附上代码:

#include<stdio.h>__int64 fun(int a,int b){    __int64 r=1,base=a;    while(b!=0)    {        if(b&1)        r=(r*base)%10;        base=(base*base)%10;        b>>=1;    }    return r%10;}int main(){    int a,b;    while(scanf("%d%d",&a,&b)==2)    {        printf("%I64d\n",fun(a,b));    }    return 0;}


0 0
原创粉丝点击