import sys
def query(input, n, weight, bias):
ans = input
for layern in range(n):
ans = ans * weight[layern] + bias[layern]
return ans
def read():
return sys.stdin.readline().strip()
def readTestCase():
[n, minX, maxX] = read().split(' ')
n = int(n)
minX = int(minX)
maxX = int(maxX)
weights = []
biases = []
for j in range(n):
a = read().split(' ')
weights.append(int(a[0]))
biases.append(int(a[1]))
spammers = 0
nonspammers = 0
for i in range(minX, maxX+1):
y = query(i, n, weights, biases)
if y % 2 == 0:
nonspammers += 1
else:
spammers+=1
return[nonspammers, spammers]
T = int(read())
for i in range(T):
print(readTestCase())
This is for the Problem SPAMCLAS.(Python 3.5)
I am getting an overtime error.
How can I optimize this code?