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 was a Singleinteger T which is the number of test cases. T test Cases follow.
Each test case is 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
234
Sample Output
76
Hint
In the first case, 3 * 3 * 3 = rightmost, so the-the-digit is 7. In the
n the N-th square, which requires only one single digit of N's side, and a rule,
1 1 1 1 1 1 1 1
2 4 8 6 2 4 8 6
3 9 7 1 3 9 7 1
4 6 4 6 4 6 4 6
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
7 9 3 1 7 9 3 1
8 4 2 6 8 4 2 6
1 9 1 9 1 9 1 9
So it should be easy to
1#include <iostream>2#include <cstdio>3 using namespacestd;4 intMain ()5 {6 intT;7 intN;8 inti,j;9 while(cin>>t)Ten { One while(t--) A { -Cin>>N; -i=n%Ten; thej=n%4; - if(j==0) -cout<<i*i*i*i%Ten<<Endl; - Else + { - intans=1; + while(j--) A { atans*=i; -ans=ans%Ten; - } -cout<<ans<<Endl; - } - } in } - return 0; to}
HDU 1061 rightmost Digit