这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE。
#include <stdio.h> #define MAXNUM 1000000001 int buf[][]; int main() {
int case_n, n;
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][]++;
}
}
/*
for (i=0; i<10; ++i) {
printf("%d:", i);
for (j=1; j<=buf[i][0]; ++j)
printf(" %d", buf[i][j]);
printf("\n");
}
*/
scanf("%d", &case_n); while (case_n--) {
scanf("%d", &n);
i = n % ;
j = n % buf[i][];
if (!j)
j = buf[i][];
printf("%d\n", buf[i][j]);
} return ;
}