标签:
求a^b的最后一位,a有1000位,b是long long。
#include<cstdio> #include<cstring> long long y; char x[1005]; int n,i,s; int a[10]; int l; int find(int s,long long r){ memset(a,0,sizeof(a)); a[0]=1; a[1]=s;a[2]=s*s%10; i=2; while(a[1]!=a[i])a[++i]=a[i-1]*s%10; if (r==0)return 1; return a[(r-1)%(i-1)+1]; } int main(){ scanf("%d",&n); while(n--){ scanf("%s%lld",&x,&y); l=strlen(x); printf("%d\n",find(x[l-1]-48,y)); } }
SPOJ Problem 5699:The last digit re-visited
标签:
原文地址:http://www.cnblogs.com/moris/p/4328383.html