Given 6 numbers a,b,c,d,e,f. Find the last digit of (a^{b})*(c^{d})*(e^{f}).
 
Example 1:
Input:
a = 3 
b = 66 
c = 6 
d = 41 
e = 7 
f = 53
Output:
8
Explanation:
The last digit of the 
value obtained after 
solving the above 
equation is 8.
 
 
Example 2:
Input:
a = 1 
b = 1 
c = 1 
d = 1 
e = 1 
f = 1
Output:
1
Explanation:
The last digit of the 
value obtained after 
solving the above 
equation is 1.
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function theLastDigit() which takes 6 integers a, b, c, d, e, and f and returns the last digit of the value obtained from the equation.
 
Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= a,b,c,d,e,f <= 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Mathematics

Starter code: #User function Template for python3
class Solution:
    def theLastDigit (self,a,b,c,d,e,f):
        # code here 


Solutions:
class Solution:

	def theLastDigit(self, a, b, c, d, e, f):
		b %= 4
		f %= 4
		d %= 4
		if not b:
			b = 4
		if not f:
			f = 4
		if not d:
			d = 4
		return (a % 10) ** b * (c % 10) ** d * (e % 10) ** f % 10