Rightmost digit
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 12357 accepted submission (s): 4773
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 input2
3
4
Sample output7
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.
Authorignatius. L is mainly used to master the Modulo-power operation, and to obtain a single digit.
# Include < Stdio. h >
# Include < Iostream >
Using Namespace STD;
Int Solve ( Long Long N)
{
Int T, B;
Long Long I;
B = N % 10 ;
T = 1 ;
If (B = 0 ) Return 0 ;
While (N)
{
If (N % 2 = 1 )
{
T * = B;
T % = 10 ;
}
B * = B;
B % = 10 ;
N /= 2 ;
}
Return T;
}
Int Main ()
{
Int T;
Long Long N;
CIN > T;
While (T -- )
{
CIN > N;
Cout < Solve (N) < Endl;
}
Return 0 ;
}