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
| #include<cstdio> #include<cstring>
int main() { const int mod[10] = { 1,1,4,4,2,1,1,4,4,2 }; const int ans[10][4] = { {0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9} }; char sm[105], sn[105]; while (scanf("%s%s", sm, sn) && (sm[0] != '0' || sn[0] != '0')) { if (sn[0] == '0') { puts("1"); continue; }
int len_m = strlen(sm), len_n = strlen(sn), m = sm[len_m - 1] - '0', n = 0;
for (int i = 0; i <len_n ; i++) { n = n * 10 + sn[i] - '0'; n %= mod[m]; }
printf("%d\n", ans[m][n]); }
return 0; }
|