Problem

Source: Baltic Way 2006

Tags: modular arithmetic, number theory proposed, number theory



For a positive integer $n$ let $a_n$ denote the last digit of $n^{(n^n)}$. Prove that the sequence $(a_n)$ is periodic and determine the length of the minimal period.