题目和1061非常相似,几乎可以复用。
#include <stdio.h> int buf[][]; int main() {
int a, b;
int i, j; for (i=; i<; ++i) {
buf[i][] = ;
buf[i][] = i;
for (j=; j<; ++j) {
buf[i][j] = buf[i][j-]*i%;
if (buf[i][j] == buf[i][])
break;
buf[i][]++;
}
} while (scanf("%d %d", &a, &b) != EOF) {
i = a % ;
j = b % buf[i][];
if (!j)
j = buf[i][];
printf("%d\n", buf[i][j]);
} return ;
}