MCPcopy Create free account
hub / github.com/geekcomputers/Python / last_digit

Function last_digit

Unit Digit of a raised to power b.py:1–9  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

1def last_digit(a, b):
2 if b == 0: # This Code assumes that 0^0 is 1
3 return 1
4 elif a % 10 in [0, 5, 6, 1]:
5 return a % 10
6 elif b % 4 == 0:
7 return ((a % 10) ** 4) % 10
8 else:
9 return ((a % 10) ** (b % 4)) % 10
10
11
12# Courtesy to https://brilliant.org/wiki/finding-the-last-digit-of-a-power/

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected