# 10515 - Powers Et Al.

 Tweet
Difficulty : easy

Solution Description :

Modular arithmetic problem

You need to calculate the last digit of m
If last digit is 0: 0^1%10=0, 0^2%10=0, 0^3%10=0, ....
If last digit is 1: 1^1%10=1, 1^2%10=1, 1^3%10=1, ....
If last digit is 2: 2^1%10=2, 2^2%10=4, 2^3%10=8, 2^4%10=6, 2^5%10=2, 2^6%10=4, 2^7%10=8, 2^8%10=6, ....
If last digit is 3: 3^1%10=3, 3^2%10=9, 3^3%10=7, 3^4%10=1, 3^5%10=3, 3^6%10=9, 3^7%10=7, 3^8%10=1, ....
If last digit is 4: 4^1%10=4, 4^2%10=6, 4^3%10=4, 4^4%10=6, ...
If last digit is 5: 5^1%10=5, 5^2%10=5, 5^3%10=5, ...
If last digit is 6: 6^1%10=6, 6^2%10=5, 6^3%10=6, ...
If last digit is 7: 7^1%10=7, 7^2%10=9, 7^3%10=3, 7^4%10=1, 7^5%10=7, 7^6%10=9, 7^7%10=3, 7^8%10=1, ....
If last digit is 8: 8^1%10=8, 8^2%10=4, 8^3%10=2, 8^4%10=6, 8^5%10=8, 8^6%10=4, 8^7%10=2, 8^8%10=6, ....
If last digit is 9: 9^1%10=9, 9^2%10=1, 9^3%10=9, 9^4%10=1, ...
So, you need to calculate maximum fist four term.

Now you can find the ans using the value (n%mod). Here value of mod can be 2 or 4
If last digit is 2, then mod=4
If last digit is 3, then mod=4
If last digit is 4, then mod=2
If last digit is 7, then mod=4
If last digit is 8, then mod=4
If last digit is 9, then mod=2

Ans If last digit are 0, 1, 5, 6 then just print the digit.

Remember if n=0 then just print 1.