CDZSC_2015寒假新人(2) 数学 C

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). 
 

Output

For each test case, you should output the rightmost digit of N^N. 
 

Sample Input

2 3 4
 

Sample Output

7 6

Hint

 In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6. 
         
 

 题目有规律, 找到规律即可。

 
 1 #include <cstdio>
 2 int Map[2][10] = {{0,1,4,7,6,5,6,3,6,9},{0,1,6,3,6,5,6,7,4,9}};
 3 int main()
 4 {
 5     int t,n;
 6     scanf("%d",&t);
 7     while (t--)
 8     {
 9         scanf("%d",&n);
10         printf("%d\n",Map[(n/10)%2][n%10]);
11     }
12     return 0;
13 }
View Code
原文地址:https://www.cnblogs.com/LiuACG/p/4246126.html