先找特殊数,枚举后发现是,以四为周期的,然后递推的公式
乘n%4+4(保证乘过)次,以n%10为母体
# include <stdio.h> int pp(int n, int m) { int i, mul = 1 ; for (i = 0 ; i < m ; i++) mul = (mul*n)%10 ; return mul % 10 ; } int main () { int T, n ; scanf ("%d", &T) ; while (T--) { scanf ("%d", &n) ; printf ("%d\n", pp(n%10, n%4 + 4)) ; } return 0 ; }