标签:style blog class code java tar
题意 : 求n的n次方的个位数是多少。
思路 : 自己写一下看一下规律,会发现0,1,5,6的个位数怎么乘都是原来这个数,剩下的数也还是有规律。
1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 5 using namespace std ; 6 7 int a[10][4] = {{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}} ; 8 9 int main() 10 { 11 int T,n ; 12 scanf("%d",&T) ; 13 while(T--) 14 { 15 scanf("%d",&n) ; 16 int s = n ; 17 n %= 10 ; 18 if(n == 0 || n == 1 || n == 5 || n == 6) 19 printf("%d\n",a[n][0]) ; 20 else if(n == 2 || n == 3 || n == 7 || n == 8) 21 printf("%d\n",a[n][s%4]) ; 22 else if(n == 4 || n == 9) 23 printf("%d\n",a[n][s%2]) ; 24 } 25 return 0 ; 26 }
HDU 1061 Rightmost Digit,布布扣,bubuko.com
标签:style blog class code java tar
原文地址:http://www.cnblogs.com/luyingfeng/p/3716451.html