-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday55.py
More file actions
36 lines (33 loc) · 911 Bytes
/
Copy pathday55.py
File metadata and controls
36 lines (33 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/python
import sys
import math
def howManyGames(p, d, m, s):
t_l = 0
if p % d != 0:
t_l = p % d
else:
t_l = d
d = -d
t_n = ((t_l-p)/d) + 1
t_sum = (t_n*(p+t_l))/2
if s > t_sum:
n = ((m-p)/d) + 1
l = p+((n-1)*d)
sn = (n*(p+l))/2
return n+((s-sn)/m)
else:
x1 = abs(int(((-((2*p)-d))+math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d)))
x2 = abs(int(((-((2*p)-d))-math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d)))
l = p+((x1-1)*d)
s1 = (x1*(p+l))/2
l = p+((x2-1)*d)
s2 = (x2*(p+l))/2
if s1 <= s:
return x1
else:
return x2
if __name__ == "__main__":
p, d, m, s = raw_input().strip().split(' ')
p, d, m, s = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print answer