Problem descriptionGiven a positive integer N, you should output the most right digit of N ^ n.
InputThe 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 ).
OutputFor each test case, You shoshould output the rightmost digit of N ^ N.
Sample Input
234
Sample output
76
It is impossible to find a legal question in a harmonious manner and to know the scale of data. In the first place, I thought that only the last bit can be used for computation to simplify computation. However, if you ignore repeated operations, it will still time out. So we can only use the result after the last digit is multiplied to get the last digit to find the rule. In fact, there is a cycle. For example, 2 ^ 2 = 4, 2 ^ 3 = 8, 2 ^ 4 = 6, 2 ^ 5 = 2, 2 ^ 6 = 4 ......
The first thing I wrote was to use if to judge all single digits. The result code was lengthy. By referring to others' practices, you can use arrays to store and simplify code.
# Include <stdio. h> <br/> int main () <br/>{< br/> int N; <br/> int A [10] [4] ={{ 0 }, {1}, {6, 2,}, {1, 3, 9, 7}, {6, 4}, {5}, {6}, {, 9, 3}, {6, 4, 2 }, {1, 9 }}, D, num; <br/> scanf ("% d", & num); <br/> while (Num --) <br/>{< br/> scanf ("% lD", & N); <br/> d = n % 10; <br/> If (D = 0 | D = 1 | D = 5 | D = 6) <br/> printf ("% d/N", d); <br/> else if (D = 4 | D = 9) <br/> printf ("% d/N", a [d] [n % 2]); <br/> else if (D = 2 | D = 3 | D = 7 | D = 8) <br/> printf ("% d/N", a [d] [n % 4]); <br/>}< br/> return 0; <br/>}< br/>