HDU 1097 (整数快速幂取模)

http://acm.hdu.edu.cn/showproblem.php?pid=1097

在数论里学到了整数的快速幂,这里居然是秒过的。。。。瞬间就知道自己以前多菜了

#include<stdio.h>
__int64 puzzle(__int64 a,__int64 b)
{
    __int64 ans=1;
    while(b)
    {
            if(b&1)
            ans=ans*a%10;
            a=a*a%10;
            b/=2;
    }
    return ans;
}
int main()
{
    __int64 a,b;
    while(scanf("%I64d%I64d",&a,&b)!=EOF)
    printf("%I64d\n",puzzle(a,b));
    return 0;
} 
View Code

 

posted @ 2013-08-16 14:28  执着追求的IT小小鸟  阅读(165)  评论(0编辑  收藏  举报