我如何减少此代码的执行时间

时间:2019-05-10 10:25:47

标签: time reduce

t= int(input())
q=[]
l=[]
x = 0
y = 0
ele = 0
s = 1
m=1000000007

def reduce(x, y):
    m = 1000000007
    ele = x + y + ((x % m * y % m) % m)
    l.remove(x)
    l.remove(y)
    l.append(ele)



for i in range(t):
    q.append(int(input()))

for n in q:
    l = list(range(1, n + 1))
    for i in range(n):
        s = len(l)
        if(s == 1):
            print(l[0]%m)

            l.clear()
        else:
            x = l[len(l) - 1]
            y = l[len(l) - 2]
            reduce(x, y)

0 个答案:

没有答案