2D. Rightmost Digit

D. Rightmost Digit

1000ms
1000ms
32768KB
 
64-bit integer IO format: %I64d      Java class name: Main
 
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.
 
 ACM 新人,水题,找规律即可
 
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <vector>
 6 #include <climits>
 7 #include <algorithm>
 8 #include <cmath>
 9 #define LL long long
10 using namespace std;
11 int main(){
12     int i,j,temp,n;
13     int d[10][10];
14     for(i = 0; i < 10; i++){
15         temp = i;
16         for(j = 0; j < 4; j++){
17             d[i][j] = temp%10;
18             temp *= i;
19         }
20     }
21     scanf("%d",&n);
22     while(n--){
23         scanf("%d",&temp);
24         printf("%d\n",d[temp%10][(temp-1)%4]);
25     }
26     return 0;
27 }
View Code

 

posted @ 2014-07-06 14:51  狂徒归来  阅读(147)  评论(0编辑  收藏  举报