Given two numbers a and b. Find the last digit of a raised to the power b.
Example 1:
Input:
a = 3
b = 4
Output:
1
Explanation:
3^{4} = 81 so the last digit is 1.
Example 2:
Input:
a = 2
b = 8
Output:
6
Explanation:
2^{8} = 256 so the last digit is 6.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function quickExponents() which take two integers a and b and returns the last digit of a raise to the power b.
Expected Time Complexity: O(Log(b))
Expected Auxiliary Space: O(1)
Constraints:
1 <= a, b <= 10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def quickExponents(self, a,b):
    	#code here 

Solutions:
class Solution:

	def quickExponents(self, a, b):

		def fast_power(a, b):
			if b == 0:
				return 1
			if b % 2 == 0:
				return fast_power(a * (a % 10), b // 2)
			else:
				return a * fast_power(a * (a % 10), b // 2) % 10
		val = fast_power(a, b)
		return val % 10


class Solution:

	def quickExponents(self, a, b):
		a1 = a % 10
		b1 = (b - 1) % 4
		while b1 > 0:
			a1 = a1 * a % 10
			b1 -= 1
		return a1


class Solution:

	def quickExponents(self, a, b):

		def findmodpow(a, b, m=1):
			res = 1
			while b > 0:
				if b & 1:
					res = res * a % 10
				a = a * a % 10
				b >>= 1
			return res
		return findmodpow(a, b) % 10