Description
Background
Give you a integer number N (1 <= n <= 2*10100). pleasecompute
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 lastdigit of S.
Sample Input
1
2
3
0
Sample output
1
5
2
Question: How many digits is s?
Idea: If you see such a large number, first create a table and try to find that every 20 items is a small loop, and every 100 items is a large loop, and the result calculation of 100 items is recorded directly.
# Include <iostream> # include <cstring> # include <algorithm> # include <cstdio> using namespace STD; const int maxn = 300; int num [maxn]; char STR [maxn]; int main () {int ans = 0; For (INT I = 1; I <= 200; I ++) {int TMP = 1; for (Int J = 1; j <= I; j ++) TMP = TMP * I % 10; ans = (ANS + TMP) % 10; num [I] = ans;} while (scanf ("% s", STR )! = EOF & STR [0]! = '0') {int Len = strlen (STR); int CNT = 0; For (INT I = 0; I <Len; I ++) CNT = (CNT * 10 + STR [I]-'0') % 100; If (! CNT) CNT = 100; printf ("% d \ n", num [CNT]);} return 0 ;}