首页 > 其他 > 详细

SPOJ Problem 3442:The last digit

时间:2015-03-04 22:29:25      阅读:304      评论:0      收藏:0      [点我收藏+]

求某数的某次幂最后一位,暴力找规律后取模。

#include<cstdio>
#include<cstring>
int t,x,y,s;
int a[20];
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&x,&y);
        s=2;x%=10;
        a[0]=1;a[1]=x;a[2]=x*x%10;
        while(a[s]!=x)a[++s]=a[s-1]*x%10;
        if (y==0)printf("1\n");else{
            y=(y-1)%(s-1)+1;
            printf("%d\n",a[y]);
        }
    }
}

 

SPOJ Problem 3442:The last digit

原文:http://www.cnblogs.com/moris/p/4314278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!