Define a function that takes in two non-negative integers `$a$` and `$b$` and returns the last decimal digit of `$a^b$`. Note that `$a$` and `$b$` may be very large!

For example, the last decimal digit of `$9^7$` is `$9$`, since `$9^7 = 4782969$`.  The last decimal digit of `$({2^{200}})^{2^{300}}$`, which has over `$10^{92}$` decimal digits, is `$6$`.  Also, please take `$0^0$` to be `$1$`.

You may assume that the input will always be valid.

## Examples

```python
last_digit(4, 1)                # returns 4
last_digit(4, 2)                # returns 6
last_digit(9, 7)                # returns 9
last_digit(10, 10 ** 10)        # returns 0
last_digit(2 ** 200, 2 ** 300)  # returns 6
```

___

## Remarks

### JavaScript, C++, R, PureScript

Since these languages don't have native arbitrarily large integers, your arguments are going to be strings representing non-negative integers instead.

Difficulty: EASY
Tags: Mathematics

Starter code:
def last_digit(n1, n2):
	

Solutions:
def last_digit(n1, n2):
	return pow(n1, n2, 10)


rules = {0: [0, 0, 0, 0], 1: [1, 1, 1, 1], 2: [2, 4, 8, 6], 3: [3, 9, 7, 1], 4: [4, 6, 4, 6], 5: [5, 5, 5, 5], 6: [6, 6, 6, 6], 7: [7, 9, 3, 1], 8: [8, 4, 2, 6], 9: [9, 1, 9, 1]}

def last_digit(n1, n2):
	ruler = rules[int(str(n1)[-1])]
	return 1 if n2 == 0 else ruler[n2 % 4 - 1]


def last_digit(n1, n2):
	return (n1 % 10) ** (n2 % 4 + 4 * bool(n2)) % 10


E = [[0, 0, 0, 0], [1, 1, 1, 1], [6, 2, 4, 8], [1, 3, 9, 7], [6, 4, 6, 4], [5, 5, 5, 5], [6, 6, 6, 6], [1, 7, 9, 3], [6, 8, 4, 2], [1, 9, 1, 9]]

def last_digit(n1, n2):
	if n2 == 0:
		return 1
	return E[n1 % 10][n2 % 4]


last_digit = lambda n1, n2: pow(n1, n2, 10)


def last_digit(n1, n2):
	m1 = n1 % 10
	if m1 == 1:
		return 1
	if m1 == 2:
		if n2 == 0:
			return 1
		elif n2 % 4 == 3:
			return 8
		elif n2 % 4 == 0:
			return 6
		elif n2 % 4 == 2:
			return 4
		else:
			return 2
	if m1 == 3:
		if n2 == 0:
			return 1
		elif n2 % 4 == 0:
			return 1
		elif n2 % 2 == 0:
			return 9
		elif n2 % 4 == 3:
			return 7
		else:
			return 3
	if m1 == 4:
		if n2 == 0:
			return 1
		elif n2 % 4 == 2 or n2 % 4 == 0:
			return 6
		else:
			return 4
	if m1 == 5:
		if n2 == 0:
			return 1
		else:
			return 5
	if m1 == 6:
		if n2 == 0:
			return 1
		else:
			return 6
	if m1 == 7:
		if n2 == 0:
			return 1
		elif n2 % 4 == 3:
			return 3
		elif n2 % 4 == 0:
			return 1
		elif n2 % 4 == 2:
			return 9
		else:
			return 7
	if m1 == 8:
		if n2 == 0:
			return 1
		elif n2 % 4 == 3:
			return 2
		elif n2 % 4 == 0:
			return 6
		elif n2 % 4 == 2:
			return 4
		else:
			return 8
	if m1 == 9:
		if n2 == 0:
			return 1
		elif n2 % 2 == 1:
			return 9
		else:
			return 1
	if m1 == 0:
		if n2 == 0:
			return 1
		return 0


def last_digit(n1, n2):
	last_dict = {0: [0], 1: [1], 2: [2, 4, 6, 8], 3: [3, 9, 7, 1], 4: [4, 6], 5: [5], 6: [6], 7: [7, 9, 3, 1], 8: [8, 4, 2, 6], 9: [9, 1]}
	if n2 == 0:
		return 1
	a = n1 % 10
	return last_dict[a][(n2 - 1) % len(last_dict[a])]


def last_digit(n1, n2):
	if n2 == 0:
		return 1
	seq = [[0], [1], [2, 4, 8, 6], [3, 9, 7, 1], [4, 6], [5], [6], [7, 9, 3, 1], [8, 4, 2, 6], [9, 1]]
	l_digit = int(str(n1)[-1])
	position = n2 % len(seq[l_digit])
	return seq[l_digit][position - 1]