高效计算 n 阶乘最右边的非零数字
我想计算给定数字的阶乘的最右边的数字并打印它。到目前为止我所做的是:
import math
n = int(input())
fact = math.factorial(n)
print(str(fact).rstrip('0')[-1])
Run Code Online (Sandbox Code Playgroud)
但我仍然受到时间限制,我寻找更快的解决方案。值得注意的是,我必须使用python来解决这个问题。
另外,我要指出的是,n是从1到65536,时间限制是0.5秒,并且我有256兆字节的内存。