我正在尝试编写一些应该在阶乘中找到尾随零的代码 . 我的问题是,当我将下面一段代码(Python3)发送给SPOJ的在线评判时,它给了我超出时间限制的错误 . 但是,如果我将语言从Python3更改为Python 2,并将 input s转换为 raw_input s,则会在3秒内接受 . 此问题的时间限制为6秒 .

这让我思考 . 这是因为 raw_input 的差异吗?据我所知,Python3没有 raw_input . 所以我不知道该做些什么来减少Python3的时间 .

def Z(n):
    count = 0
    while n >= 5:
        n //= 5
        count += n
    return int(count)  

for i in range(int(input())): #get the number of test cases
print(Z(int(input()))) # get trailing zeros

有关问题输入的更多信息

输入第一行输入上有一个正整数T(等于约100000) . 它代表要遵循的数字数量 . 然后有T行,每行包含正整数N,1 <= N <= 1000000000 .