hdu 1061 Rightmost Digit

时间:2014-08-20 18:02:42   收藏:0   阅读:314
//模幂运算,而且求个位,一直求10的模
# include <stdio.h>
# include <algorithm>
# include <math.h>
using namespace std;
__int64 Pow(__int64 m,__int64 n)
{
    __int64 p=1;
    while(n)
    {
        if(n%2)
            p=p*m%10;
        n/=2;
        m=m*m%10;
    }
    return p%10;
}
int main()
{
    int t;
    __int64 n,m;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%I64d",&n);
            m=n;
            m%=10;//求个位的n次取模
            if(m==0)
                printf("0\n");
            else
                printf("%I64d\n",Pow(m,n));
        }
    }
    return 0;
}

hdu 1061 Rightmost Digit,布布扣,bubuko.com

原文:http://blog.csdn.net/lp_opai/article/details/38708241

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!