rightmost Digit
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 33823 Accepted Submission (s): 12912
Problem 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 single integer 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
2
3
4
Sample Output
7
6
Hint
In the first case, 3 * 3 * 3 = digit, so the rightmost is 7.In the second case, 4 * 4 * 4 * 4 = at the first, so the rightmost D Igit is 6.
The number of n^n per digit is at most the product of a period of 4, so as long as the maximum of four times per number of products, due to the large number, so first of all, the mantissa is required to do the product, otherwise it will explode.
Code:
#include <stdio.h>int main () {int n,a,b,ans;scanf ("%d", &n), while (n--) {scanf ("%d", &a), B = (A-1)%4+1; The maximum is 4 for the period, so to 4 to take the remainder a = a%10; The mantissa must be multiplied before it will explode if (b==1) ans = a;if (b==2) ans = a*a;if (b==3) ans = a*a*a;if (b==4) ans = A*a*a*a;ans = ans%10;
Rightmost Digit (HDU 1061)