Official

B - A^B^C Editorial by evima


For integers \(A, i\), the ones digit of the decimal notation of \(A^i\) has a period of \(4\) over \(i\). That is, instead of using \(B^C\) itself, we can use the remainder of \(B^C\) when divided by \(4\) (if the remainder is \(0\), we see it as \(4\)) to find the ones digit of \(A^{B^C}\) in the decimal notation.

For integers \(B, C\), the ones digit of the decimal notation of \(B^C\) basically has a period of \(2\) over \(C\). That is, instead of using \(C\) itself, we can basically use the parity of \(C\) to find the remainder of \(A^{B^C}\) when divided by \(4\). The exception is when the remainder of \(B\) divided by \(4\) is \(2\) and \(C\) is odd, in which case the remainder of \(B^C\) divided by \(4\) is \(2\) when \(C=1\) and \(0\) otherwise.

posted:
last update: