Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=1061
Topic Type:
Water problem
Test Instructions Summary:
n the number of bits in the nth order.
Problem Solving Ideas:
Because the range of n is too large, so I pass the number of bits to 1-9 to make 20 times to hit the table, found that their cycle is not 4, is 4 factor, so I have a number of digits 1-9 for the table four times, and then the number of input only to determine the number of single digits, and then judge the number in the first few cycles and output
Topic:
Rightmost Digit
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 55914 Accepted Submission (s): 21129
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 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).
Outputfor Each test case, you should output the rightmost digit of n^n.
Sample Input234
Sample Output76
HintIn 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.
# include <stdio.h># include<string.h>intMain () {intI,j,t,n,x,y; inta[Ten][Ten]; Memset (A,0,sizeof(a)); for(i=1;i<Ten; i++) {a[i][1]=i; for(j=2;j<5; j + +) {A[i][j]=a[i][j-1]*i%Ten; } a[i][0]=a[i][4]; } scanf ("%d",&t); while(t--) {scanf ("%d",&N); X=n%Ten; Y=n%4; printf ("%d\n", A[x][y]); }}
hdu-1061 rightmost Digit