-
Notifications
You must be signed in to change notification settings - Fork 15
/
draupnir.py
52 lines (47 loc) · 1.25 KB
/
draupnir.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
51
52
# Copyright (c) 2019 kamyu. All rights reserved.
#
# Google Code Jam 2019 Round 1B - Problem B. Draupnir
# https://codingcompetitions.withgoogle.com/codejam/round/0000000000051706/0000000000122837
#
# Time: O(1)
# Space: O(1)
#
import sys
def draupnir():
Q = Q1 # 185
print Q
sys.stdout.flush()
N = input()
R6 = (N % 2**(Q//5)) // 2**(Q//6)
R5 = (N % 2**(Q//4)) // 2**(Q//5)
R4 = (N % 2**(Q//3)) // 2**(Q//4)
Q = Q2 # 38
print Q
sys.stdout.flush()
N = input()
N -= R4 * 2**(Q//4) + R5 * 2**(Q//5) + R6 * 2**(Q//6)
R3 = (N % 2**(Q//2)) // 2**(Q//3)
R2 = (N % 2**(Q//1)) // 2**(Q//2)
R1 = N // 2**(Q//1)
print R1, R2, R3, R4, R5, R6
sys.stdout.flush()
verdict = input()
if verdict == -1: # error
exit()
R = 100
P = 63
Q = 1
floor_log2_R = R.bit_length()-1 # ceil_log2_R = (R-1).bit_length()
while (Q//2) <= floor_log2_R + (Q//3): # while 2**(Q//2) <= R * 2**(Q//3):
Q +=1
assert(2**(Q//2) > R * 2**(Q//3) and
R * 2**(Q//1) < 2**P)
Q2 = Q
while (Q//5) <= floor_log2_R + (Q//6): # while 2**(Q//5) <= R * 2**(Q//6):
Q +=1
assert(2**(Q//5) > R * 2**(Q//6) and
R * 2**(Q//4) < 2**P)
Q1 = Q
T, W = map(int, raw_input().strip().split())
for case in xrange(T):
draupnir()