Problem Description
Given a positive integer N, you should output the most right digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
2 3 4
Sample Output
7 6
一道提倡和谐的找规律题目,看到数据规模就知道暴力是不可能的了。一开始我想,只去最后一位来计算便可以简化计算,但是忽略了重复那么多次依然会让你超时。所以只能通过最后一位数相乘后的结果取最后一位来找规律,其实是有周期的。如2^2=4,2^3=8,2^4=6,2^5=2,2^6=4……
最先我写得是用IF判断所有个位数的情况,结果代码冗长。参考他人的做法,可以用数组来储存,简化代码。