-
Notifications
You must be signed in to change notification settings - Fork 14
/
28.c
69 lines (68 loc) · 1.42 KB
/
28.c
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
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <math.h>
int main(void) {
int N, a, b, n, d, l;
scanf("%d", &N);
while(N>0) {
scanf("%d %d", &a, &b);
if(a>=0 && a<=30 && b>=0 && b<=pow(10, 12)) {
d = a%10;
switch(d) {
case 0: if(b==0) printf("Undefined.\n");
else printf("0\n");
break;
case 1: printf("1\n"); break;
case 2: l = b%4;
switch(l) {
case 1: printf("2\n"); break;
case 2: printf("4\n"); break;
case 3: printf("8\n"); break;
default: printf("6\n");
}
break;
case 3: l = b%4;
switch(l) {
case 1: printf("3\n"); break;
case 2: printf("9\n"); break;
case 3: printf("7\n"); break;
default: printf("1\n");
}
break;
case 4: l = b%2;
switch(l) {
case 1: printf("4\n"); break;
default: printf("6\n");
}
break;
case 5: printf("5\n"); break;
case 6: printf("6\n"); break;
case 7: l = b%4;
switch(l) {
case 1: printf("7\n"); break;
case 2: printf("9\n"); break;
case 3: printf("3\n"); break;
default: printf("1\n");
}
break;
case 8: l = b%4;
switch(l) {
case 1: printf("8\n"); break;
case 2: printf("4\n"); break;
case 3: printf("2\n"); break;
default: printf("6\n");
}
break;
case 9: l = b%2;
switch(l) {
case 1: printf("9\n"); break;
default: printf("1\n");
}
break;
default: printf("Error.\n");
}
}
else printf("a or b not in range.\n");
N--;
}
return 0;
}