-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhatbase.py
More file actions
45 lines (30 loc) · 926 Bytes
/
whatbase.py
File metadata and controls
45 lines (30 loc) · 926 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
37
38
39
40
41
42
43
44
45
# import time
# start_time = time.time()
with open("whatbase.in","r") as f_in:
K = int(f_in.readline())
base = []
for _ in range(K):
x = f_in.readline().split()
base.append([x[0],x[1]])
def evaluate(inum,ibase):
return( int(inum[0]) * ibase * ibase + int(inum[1]) * ibase + int(inum[2]))
result = []
for i in range(K):
num1 = base[i][0]
num2 = base[i][1]
X = 10
Y = 10
while X <= 15000 and Y <= 15000:
N_X = evaluate(num1,X)
N_Y = evaluate(num2,Y)
if N_X < N_Y:
X += 1
elif N_X > N_Y:
Y += 1
else:
result.append([X, Y])
break
with open("whatbase.out", "w") as f_out:
for i in range(K):
f_out.write(str(result[i][0]) + " " + str(result[i][1]) + "\n")
# print("time elapsed: {:.2f}s".format(time.time() - start_time))