-
Notifications
You must be signed in to change notification settings - Fork 0
/
2013_r1a_pa.py
50 lines (43 loc) · 1.04 KB
/
2013_r1a_pa.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''
Created on Apr 25, 2014
@author: ezonghu
'''
def inks(r,n):
return 2*n**2+(2*r-1)*n
def solve(r,t):
import math
n=(math.sqrt((2*r-1)**2+8*t)-(2*r-1))/4
return int(n)
def solve2(r,t):
res, lo, hi = 0, 1, t
while lo <= hi:
mid = (lo + hi) / 2
if inks(r, mid) > t:
hi = mid - 1
else:
lo, res = mid + 1, mid
return res
# print solve2(1,9)
# print solve2(1,10)
# print solve2(3,40)
# print solve2(1, 1000000000000000000)
# print solve2(10000000000000000, 1000000000000000000)
def process():
fn="C:\Users\ezonghu\Downloads\A-large-practice"
fi=open(fn+'.in')
fo=open(fn+'.out','w')
first_line = fi.readline()
Cases = int(first_line)
CaseId = 0
for l in fi:
[r, t] = [int(i) for i in l.split()]
res = solve2(r, t)
CaseId += 1
Output = "Case #%d: %s" % (CaseId, res)
print(Output)
fo.write(Output+'\n')
if Cases == CaseId:
break
fi.close()
fo.close()
process()