SPOJ Problem 3442:The last digit
求某数的某次幂最后一位,暴力找规律后取模。
#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]); } } }
posted on 2015-03-04 20:47 problemcutter 阅读(127) 评论(0) 收藏 举报
浙公网安备 33010602011771号