The problem gives us an integer $n$ which can be extremely large (can exceed any integer type of your programming language) and we need to calculate the value of the given expression .
$$(1^n+2^n+3^n+4^n)\mod5$$
I came across this solution but couldn't get any of its steps so , I understand $a^{\phi(n)}=1 \mod n $
at the end according to solution we just need to check
if( n%4==0 )
printf("4");
else
printf("0");

$\phi(5)=4$ and $m^{4} \equiv 1 \pmod 5$ for $m \in \{1,2,3,4\}$
so $m^{4a+b} \equiv m^b \pmod 5$ for $m \in \{1,2,3,4\}$
so $1^{4a+b} +2^{4a+b} +3^{4a+b} +4^{4a+b} \equiv 1^{b} +2^{b} +3^{b} +4^{b} \pmod 5$
so you only need to check $1^{b} +2^{b} +3^{b} +4^{b} \pmod 5$ for small $b$, and this does indeed give $0,0,0,4,\ldots$ for $b=1,2,3,4,\ldots$ with the pattern repeating