d=[1,1,2,6,4,2,2,4,2,8]
def last_digit(n):
if n<10:
return d[n]
m=n//10
if m%2==0:
return (6*last_digit(n//5)*last_digit(n%10))%10
else:
return (4*last_digit(n//5)*last_digit(n%10))%10
def to_base5(n):
if n == 0:
return '0'
lst = []
while n > 0:
q, r = divmod(n, 5)
lst.append(r)
n = q
return lst[::-1]
seq = [
[[0,6,2,6,4],[2,2,4,2,8],[4,4,8,4,6],[6,6,2,6,4],[8,8,6,8,2]],
[[0,2,8,8,4],[2,4,6,6,8],[4,8,2,2,6],[6,2,8,8,4],[8,6,4,4,2]],
[[0,4,2,4,4],[2,8,4,8,8],[4,6,8,6,6],[6,4,2,4,4],[8,2,6,2,2]],
[[0,8,8,2,4],[2,6,6,4,8],[4,2,2,8,6],[6,8,8,2,4],[8,4,4,6,2]]
]
def ld(n):
lst = to_base5(n)
m = len(lst)
s = 0
for i, d in enumerate(lst):
s = seq[(m - 1 - i) % 4][s // 2][d]
return s
from random import randint
n = randint(10**51, 10**67)
a, b = ld(n), last_digit(n)
print(a, b)
To embed this program on your website, copy the following code and paste it into your website's HTML: