解题报告:1097的翻版,求 N^N 次方的个位是多少?
详见我的另一篇HDU 1097 A hard puzzle稍加修改就行
1 #include<cstdio> 2 int main( ) { 3 int xh[20],n,a,N,T; 4 scanf("%d",&T); 5 while(T--) { 6 scanf("%d",&N); 7 a = N; 8 xh[1] = a = a%10; 9 xh[0] = 1,n = 0; 10 for(int i = 2;i<=10;++i) { 11 xh[i] = (xh[i-1] * a) % 10; 12 if(!n && xh[i] == xh[1]) 13 n = i-1; 14 } 15 printf("%d ",N%n==0&&N!=0? xh[n]:xh[N%n]); 16 } 17 }