-
Notifications
You must be signed in to change notification settings - Fork 2
/
10162.cpp
60 lines (52 loc) · 767 Bytes
/
10162.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<string.h>
#define MAXN 202
int A[MAXN];
int N;
char DD[MAXN];
void LastD(int n) {
int i, j, k;
k = n % 10;
if(k == 0 || k == 1 || k == 6 || k == 5) {
N += k;
N = N %10;
return;
}
j = 1;
for(i = 1; i<=n; i++) {
j *= n;
j %= 10;
}
N+= j;
N %= 10;
}
void Gen() {
int i;
N = 0;
for(i = 1; i<=100; i++){
LastD(i);
A[i] = N;
}
}
int KEY() {
int i, k= 0, c = 1,sum = 0;
int l = strlen(DD);
for(i = l-1; i>=0; i--) {
sum= (DD[i] - '0') * c;
k += sum;
c *= 10;
if(c == 100) break;
}
return k;
}
int main() {
int i;
Gen();
while(1) {
scanf("%s",DD);
if(!strcmp(DD,"0")) break;
i = KEY();
printf("%d\n",A[i]);
}
return 0;
}