Basically, I have written such a program which could acquire the last digit of large numbers. However, at a certain point it crashed due to timeout. Actually, it doesn't have an exact error popped up but still takes a whole lot more time to process the entire code.
Here is my program:
def last_digit(n1, n2):
number = n1**n2
number_list = str(number).split()
return number_list[0][-1]
print(last_digit(3715290469715693021198967285016729344580685479654510946723, 68819615221552997273737174557165657483427362207517952651))
I was expecting to get the last digit of the equation. I wanna get rid of timeout and quickly solve that problem. I am open to all suggestions thanks in advance!
3715290469715693021198967285016729344580685479654510946723 ** 68819615221552997273737174557165657483427362207517952651
is too much to calculate. If you try, it'll never finish. You can try with much smaller numbers and gradually increase them to get a sense of the problem.
The task basically requires some very specific knowledge, not general programming skills. You want to use the pow
function. Take a look at the docs: https://docs.python.org/3/library/functions.html#pow
You may also want to look up "python mod" to understand what %
means, although the point is not to use %
, but something equivalent.