What is the remainder when 5 to the 999,999th power is divided by 8?
It is the same as taking 5 to the power one 9:
5^9==1,953,125 mod 8 == 5 - the remainder.
Whenever you have 5 to an odd number exponent and divide this value by 8, your remainder is 5.
Whenever you have 5 to an even number exponent and divide this value by 8, your remainder is 1.