You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

24 lines
589 B

from math import pow, ceil, floor
lines = [l.split() for l in open("input.txt", 'r').read().splitlines()]
races = [(int(lines[0][i]), int(lines[1][i])) for i in range(1,len(lines[0]))]
#[(time, record)]
#d = t * v
#charge + t = time
#t = time - charge
#v = charge
#d = (time - charge) * charge
#d = -charge^2 + time*charge
summa = 1
for race in races:
a = -1
b = race[0]
c = -race[1]
rangeStart = floor((-b + pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) + 1
rangeEnd = ceil((-b - pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) - 1
summa *= (rangeEnd-rangeStart+1)
print(summa)