Ultraviolet A 10162-last digit
Question Link
Question: PleaseS= (11 + 22 +...NN) % 10
Idea: Play 0-9 each cycle, the Discovery cycle is 1 or 2 or 4, so s is 20 cycles, after the table is typed, it is found that 20 is 4, so the corresponding 40 is 8, 60 is 6,100 is 0,100 is 1 cycle, and is 0, so first put the number mod 100, and then find the corresponding position in mod 20.
Code:
#include <stdio.h>#include <string.h>const int Z2[10] = {0, 4, 8, 2 ,6};int T[10][10], tn[10];int Z[25];char str[105];int solve(int mod) { int len = strlen(str); int yu = 0; for (int i = 0; i < len ;i++) {yu = (yu * 10 + str[i] - '0') % mod; } return yu;}int main() { for (int i = 0; i < 10; i++) {int tmp = i;T[i][tn[i]++] = i;tmp = tmp * i % 10;while (tmp != i) { T[i][tn[i]++] = tmp; tmp = tmp * i % 10;} } for (int i = 1; i <= 20; i++) {int tmp = i % tn[i % 10] - 1;if (tmp < 0) tmp += tn[i % 10];Z[i] = (Z[i - 1] + T[i % 10][tmp]) % 10; } /*for (int i = 1; i <= 20; i++)printf("%d\n", Z[i]); for (int i = 0; i < 10; i++) {printf("%d: zhouqi %d:\n", i, tn[i]);for (int j = 0; j < tn[i]; j++) printf("%d ", T[i][j]);printf("\n"); }*/ while (~scanf("%s", str) && str[0] != '0') {int yu = solve(100);int ans = (Z[yu % 20] + Z2[yu / 20]) % 10;printf("%d\n", ans); } return 0;}