Problem B. last digit
Background
Give you a integer number N (1 <= n <= 2*10100). Please compute
S = 11 + 22 + 33 +... + NN
Give the last digit of S to me.
Input
Input File consists of several NS, each n a line. It is ended with n = 0.
Output
For each n give a line containing only one digit, which is the last digit of S.
Sample Input
1
2
3
0
Sample output
1
5
2
# Include <iostream> # Include < String > Using Namespace STD; Const Int Maxn = 101 ; Int Sum [maxn]; Int Myfun (Int N ){ Int Ans = 1 ; Int Len = n % 100 ; N = N % 10 ; For ( Int I = 1 ; I <= Len; I ++ ) Ans = (ANS * n) % 10 ; Return Ans ;} Int Main (){ For ( Int I = 1 ; I <= 100 ; I ++ ) Sum [I] = (Sum [I- 1 ] + Myfun (I) % 10 ; String S; While (CIN> S & S [ 0 ]! = ' 0 ' ){ Int N; If (S. Length ()> = 2 ) N = S [S. Length ()- 1 ]- ' 0 ' +10 * (S [S. Length ()- 2 ]- ' 0 ' ); Else N = S [S. Length ()- 1 ]- ' 0 ' ; Cout <Sum [N] < " \ N " ;}}
Simple simulation with a cycle of 100.