description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
x = int(input())
for i in range(x):
z = input()
z = z.split(" ")
a = int(z[0])
b = int(z[1])
if a == b:
print(0)
elif b == 0:
print(-1)
elif b == 1:
if a == 0:
print(1)
else:
print(-1)
else:
s = bin(b - 1)[2:].count("1") - bin(a)[2:].count("1") + 1
if s <= 0:
print(2)
else:
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
k = -1
for i in range(0, t):
a, b = input().split()
a = int(a)
b = int(b)
bq = b - 1
c = bin(a)
c = str(c)
cc = bin(bq)
cc = str(cc)
a1 = c.count("1")
a0 = c.count("0")
b1 = cc.count("1")
b0 = cc.count("0")
if b == 0 and a != 0:
k = -1
elif a == b:
k = 0
elif b == 1 and a != 0:
k = -1
else:
k = b1 - a1 + 1
if k < 1:
k = 2
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
while t > 0:
t -= 1
a, b = input().split(" ")
a, b = int(a), int(b)
p = (b & -b).bit_length()
if b == 0 and a != 0:
print("-1")
elif a == b:
print("0")
elif b == 1 and a != 0:
print("-1")
else:
c1 = bin(a).count("1")
c2 = bin(b - 1).count("1")
m = c2 - c1 + 1
if m <= 0:
m = 2
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def Binary(dec):
return bin(dec)[2:]
def counter(list01, list02):
count11 = 0
count12 = 0
for i in range(0, len(list01)):
if list01[i] == 1:
count11 += 1
for j in range(0, len(list02)):
if list02[j] == 1:
count12 += 1
return [count11, count12]
t = int(input())
while t > 0:
a, b = map(int, input().split())
if a == b:
count = 0
elif b == 0:
count = -1
elif b == 1:
if a == 0:
count = 1
else:
count = -1
else:
alist = list(map(int, Binary(a)))
blist = list(map(int, Binary(b - 1)))
res = counter(alist, blist)
if res[1] >= res[0]:
count = res[1] - res[0] + 1
else:
count = 2
print(count)
t -= 1
|
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def fn(n):
b = "{0:b}".format(n)
return b.count("1")
def bins(a, b):
if a == b:
return 0
if b == 0:
return -1
if b == 1:
if a == 0:
return 1
else:
return -1
c = fn(b - 1) - fn(a) + 1
if c > 0:
return c
else:
return 2
nTestCases = int(input())
while nTestCases > 0:
a, b = input().split()
a, b = int(a), int(b)
print(bins(a, b))
nTestCases -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
T = int(input())
for i in range(T):
A, B = map(int, input().split())
Abin = str("{0:b}".format(A))
Bbin = str("{0:b}".format(B - 1))
count1B = Bbin.count("1")
count1A = Abin.count("1")
if B == 0:
if A == 0:
print(0)
else:
print(-1)
elif A == B:
print(0)
elif B == 1:
if A == 0:
print(1)
else:
print(-1)
elif count1A == count1B:
print(1)
elif count1A < count1B:
print(1 + count1B - count1A)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def f(a, b):
n1 = "{0:b}".format(a)
n2 = "{0:b}".format(b - 1)
c1, c2 = n1.count("1"), n2.count("1")
if c2 >= c1:
return 1 + c2 - c1
return 2
t = int(input())
for x1 in range(t):
a, b = map(int, input().split())
if a == b:
ans = 0
elif a == 0 and b == 1:
ans = 1
elif b == 0 or b == 1:
ans = -1
else:
ans = f(a, b)
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
z = input().split()
z = [int(j) for j in z]
a = bin(z[0])[2:]
b = bin(z[1])[2:]
rev = b[::-1]
c = 0
for l in rev:
if l == "1":
break
else:
c += 1
c1 = 0
c1 = a.count("1")
c2 = b.count("1")
if z[0] == z[1]:
print(0)
elif z[1] == 0:
print(-1)
elif z[1] == 1:
if z[0] == 0:
print(1)
else:
print(-1)
else:
p = c2 - c1 + c
if p > 0:
print(p)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
a, b = [int(i) for i in input().split()]
bin_a = bin(a)
bin_b = bin(b)
na = bin_a.count("1")
nb = bin_b.count("1")
if a == b:
print(0)
elif a == 0 and b == 1:
print(1)
elif b == 1 or b == 0:
print(-1)
elif na == nb:
c = 0
if bin_b.endswith("1"):
print(2)
else:
for j in bin_b[::-1]:
if j != "1":
c += 1
else:
break
print(c)
elif na < nb:
c = 0
for j in bin_b[::-1]:
if j != "1":
c += 1
else:
break
print(nb - na + c)
else:
c = 0
bn = bin(b - 1)
bnn = bn.count("1")
ans = bnn - na + 1
if ans > 0:
print(ans)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer β the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$0 β€ A, B β€ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B β€ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for _ in range(int(input().strip())):
a, b = map(int, input().split())
if a == b:
print("0")
elif b == 0:
print("-1")
elif b == 1:
if a == 0:
print("1")
else:
print("-1")
else:
c = 0
c1 = 0
d = 0
d1 = 0
dec = 1
if a == 0:
c = 0
while a > 0:
c1 = c1 + (a & 1)
if dec == 1:
if a & 1:
dec = 0
else:
c += 1
a = a // 2
dec = 1
if b == 0:
d = 1
while b > 0:
d1 = d1 + (b & 1)
if dec == 1:
if b & 1:
dec = 0
else:
d += 1
b = b // 2
r = d + d1 - c1
if r > 0:
print(r)
else:
print("2")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def potu(n):
return 2 ** (len(bin(n)) - 3)
def f(N, numTurns=0):
if N == 1:
return numTurns
elif potu(N) == N:
return f(int(N / 2), numTurns + 1)
else:
return f(int(N - potu(N)), numTurns + 1)
T = int(input())
for i in range(T):
N = int(input())
if f(N) % 2 == 1:
print("Louise")
else:
print("Richard")
|
FUNC_DEF RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF NUMBER IF VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def moves(n):
res = 0
while n % 2 == 0:
res += 1
n //= 2
while n != 1:
if n % 2 == 1:
res += 1
n //= 2
return res
for _ in range(int(input())):
n = int(input())
print("Richard" if moves(n) % 2 == 0 else "Louise")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def counter_game(c):
i = 0
while int(c) > 1:
tmp = "1" + "0" * (len(c) - 1)
if c == tmp:
c = tmp[:-1]
else:
c = bin(int(c, 2) - int(tmp, 2)).lstrip("0b")
i += 1
if i % 2 == 0:
print("Richard")
else:
print("Louise")
for _ in range(int(input())):
_c = bin(int(input())).lstrip("0b")
counter_game(_c)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def turn(a):
t = 0
for i in range(len(a)):
if a[i] == "1":
t += 1
if t == 2:
return "0b" + a[i:]
return a[:-1]
for i in range(int(input())):
n = int(input())
turns = 0
a = bin(n)
while a != "0b1":
turns += 1
a = turn(a)
if turns % 2 == 1:
print("Louise")
else:
print("Richard")
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN BIN_OP STRING VAR VAR RETURN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for t in range(int(input())):
k = 0
n = int(input())
d = 2**63
while n > 1:
while d >= n:
d //= 2
n -= d
k += 1
print(["Richard", "Louise"][k % 2])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
while t > 0:
n = int(input())
x = bin(n)[2:]
winner = 0
while len(x) > 1:
if x[1:].count("1") == 0:
x = x[: len(x) - 1]
else:
x = x[1:]
while x[0] == "0":
x = x[1:]
winner = (winner + 1) % 2
if winner == 1:
print("Louise")
else:
print("Richard")
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR NUMBER STRING NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for t in range(T):
N = int(input())
N_bin = "{0:064b}".format(N)
zero_num = 0
while N_bin[63 - zero_num] == "0":
zero_num += 1
one_num = 0
for i in range(64):
if N_bin[i] == "1":
one_num += 1
a = (one_num - 1 + zero_num) % 2
if a:
print("Louise")
else:
print("Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
winner = 0
def is_power2(num):
return num != 0 and num & num - 1 == 0
def powerof2(num):
i = 0
while i <= 64:
if int(num / pow(2, i)) == 0:
return i
else:
i = i + 1
for i in range(0, T):
Number = int(input())
winner = 0
if Number == 1:
print("Louise")
continue
if is_power2(Number) == 1:
Number = int(Number - Number / 2)
else:
Number = Number - pow(2, powerof2(Number) - 1)
while Number > 1:
winner = ~winner
if is_power2(Number) == 1:
Number = int(Number - Number / 2)
else:
Number = Number - pow(2, powerof2(Number) - 1)
if winner == 0:
print("Louise")
else:
print("Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
inputno = int(input())
cases = []
while inputno > 0:
inputno -= 1
val = int(input())
cases.append(val)
def fiddle(num):
binnum = bin(int(num))
strlen = len(binnum) - 2
string = "0b1" + "0" * (strlen - 1)
if binnum == string:
return num / 2
intofstring = int(string, 2)
laststring = int(binnum, 2) & intofstring
return int(num - laststring)
def winner(case):
if case == 1:
return 0
return int(winner(fiddle(case)) + 1)
for case in cases:
if winner(case) % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def calculate_new_n(n):
for i in range(64, -1, -1):
pow_n = 1 << i
if pow_n == n:
n //= 2
return n
if pow_n < n:
n -= pow_n
return n
for _ in range(int(input())):
counter = int(input())
current_player = 0
while 1:
counter = calculate_new_n(counter)
if counter == 1:
str = "Richard" if current_player == 1 else "Louise"
print(str)
break
else:
current_player ^= 1
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER RETURN VAR IF VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
cases = int(input())
def next(val):
indx = 0
while 1 < val:
val = val >> 1
indx += 1
return 2**indx
for i in range(cases):
n = int(input())
louise = True
while True:
if n & n - 1 == 0:
n = n >> 1
else:
n = n - next(n)
if n == 1:
print("Louise" if louise else "Richard")
break
else:
louise = False if louise else True
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
def lsb(x):
n = int(x)
count = 0
while n & 1 == 0:
n >>= 1
count += 1
return count
def nbits(x):
n = int(x)
count = 0
while n > 0:
count += n & 1
n >>= 1
return count
def num_ops(N):
if N == 1:
return 1
else:
pass
for i in range(T):
N = int(input())
rounds = nbits(N) - 1 + lsb(N)
if rounds % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for i in range(int(input())):
n = int(input())
binary = str(bin(n))[-1:1:-1]
count1 = binary.count("1")
count2 = binary.index("1")
print("Richard" if (count1 + count2) % 2 == 1 else "Louise")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
def run(n):
c = 0
while n != 1:
j, base = 0, 1
while base * 2 <= n:
base *= 2
j += 1
if base == n:
c += j
break
else:
c += 1
n -= base
if c % 2 == 0:
print("Richard")
else:
print("Louise")
for i in range(t):
run(int(input()))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
two_powers = [(1 << i) for i in range(64)]
def moves(n):
if n == 1:
return 0
elif n in two_powers:
return 1 + moves(n // 2)
else:
largest_power = 0
for i in reversed(range(len(two_powers))):
if n > two_powers[i]:
largest_power = two_powers[i]
break
return 1 + moves(n - largest_power)
for _ in range(int(input())):
if moves(int(input())) % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def f(n):
ret = 1
while ret <= n:
ret *= 2
return ret // 2
for t in range(int(input())):
n, k = int(input()), 0
while True:
if n == 1:
break
if f(n) == n:
n //= 2
else:
n -= f(n)
k ^= 1
print("Richard" if not k else "Louise")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
lst = [(2**i) for i in range(65)]
for i in range(int(input())):
n = int(input())
counter = 0
while n != 1:
j = 0
while lst[j + 1] < n:
j += 1
n -= lst[j]
counter += 1
if counter % 2 == 0:
print("Richard")
continue
print("Louise")
|
ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def nextPowerOf2(n):
n = n - 1
n = n | n >> 1
n = n | n >> 2
n = n | n >> 4
n = n | n >> 8
n = n | n >> 16
n = n + 1
return n
def main():
tt = int(input())
num = []
name = []
for i in range(tt):
a = int(input())
num.append(a)
for i in range(tt):
c = 1
counter = num[i]
while counter != 1:
a = nextPowerOf2(counter)
if a != counter:
a = a // 2
else:
a = counter // 2
counter = counter - a
c = c + 1
c = c - 1
if c % 2 == 0:
name.append("Richard")
else:
name.append("Louise")
for i in range(tt):
print(name[i])
main()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
cases = int(input())
s = {(0): "Richard", (1): "Louise"}
def solve(n):
c = 0
while n != 1:
c += 1
if n % 2 == 0:
n >>= 1
else:
sub = 1 << len(str(bin(n))) - 3
n -= sub
print(s[c % 2])
for case in range(cases):
n = int(input())
solve(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for _ in range(int(input())):
N = int(input()) - 1
N = (N & 6148914691236517205) + (N >> 1 & 6148914691236517205)
N = (N & 3689348814741910323) + (N >> 2 & 3689348814741910323)
N = (N & 1085102592571150095) + (N >> 4 & 1085102592571150095)
N = (N & 71777214294589695) + (N >> 8 & 71777214294589695)
N = (N & 281470681808895) + (N >> 16 & 281470681808895)
N = (N & 4294967295) + (N >> 32 & 4294967295)
print("Richard" if N % 2 == 0 else "Louise")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for i in range(T):
N = int(input())
richard = True
while N > 1:
richard = not richard
k = 1
while 2 * k < N:
k = k * 2
N = N - k
if richard:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for _ in range(int(input())):
N = bin(int(input()))
p = "Louise"
while True:
if N.count("1") == 1:
N = N[:-1]
else:
i = N.index("1")
N = N[:i] + N[i + 1 :]
if N.count("1") == 1 and N[-1] == "1":
print(p)
break
p = "Richard" if p == "Louise" else "Louise"
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING WHILE NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def is_power_of_two(num):
bin_string = bin(num)[2:]
if bin_string.count("1") != 1:
return False
return True
def largest_power_of_two_less_than(num):
if is_power_of_two(num):
return 2 ** (num.bit_length() - 2)
else:
return 2 ** (num.bit_length() - 1)
t = int(input())
for _ in range(t):
n = int(input())
moves = 0
while n != 1:
moves += 1
if is_power_of_two(n):
n -= n // 2
else:
n -= largest_power_of_two_less_than(n)
if moves % 2 == 0:
print("Richard")
else:
print("Louise")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def isPowerOf2(N):
M = N
n1 = 0
for i in range(64):
if M & 1 == 1:
n1 += 1
M = M >> 1
return n1 == 1
def reduceByLargestPowerOf2LessThanN(N):
M = N
i = 0
while M != 1:
i += 1
M = M >> 1
mask = 2**i
return N ^ mask
def halveN(N):
return N >> 1
numTests = int(input())
for i in range(numTests):
N = int(input())
towin = "Richard"
while N > 1:
if isPowerOf2(N):
N = halveN(N)
else:
N = reduceByLargestPowerOf2LessThanN(N)
towin = "Louise" if towin == "Richard" else "Richard"
print(towin)
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for _ in range(T):
N = int(input())
one = 1 << 63
count = 0
while N > 1:
while one > N:
one >>= 1
if N == one:
N >>= 1
else:
N -= one
count += 1
if count % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
a = "Louise"
b = "Richard"
d = int(input())
def ispower(n):
for i in range(1, 65):
if n == pow(2, i):
return True
return False
def powto(n):
if not ispower(n):
for i in range(1, 65):
if n - pow(2, i) < 0:
return pow(2, i - 1)
for e in range(d):
c = 1
f = int(input())
while f != 1:
c = c + 1
if ispower(f):
f = int(f / 2)
else:
f = f - powto(f)
if c % 2 == 0:
print(a)
else:
print(b)
|
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR FUNC_CALL VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
twosList = list(reversed([(2**i) for i in range(64)]))
twosSet = {(2**i) for i in range(64)}
def powerOfTwo(n):
for e in twosList:
if e < n:
return e
N = int(input())
for numTest in range(N):
curr = int(input())
ops = 0
while curr != 1:
if curr in twosSet:
curr /= 2
else:
curr = curr - powerOfTwo(curr)
ops += 1
if ops % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
arr_2_power = [None] * 65
for i in range(1, 65):
arr_2_power[i] = 2**i
T = int(input())
for t in range(T):
counter = int(input())
turn = 0
while counter != 1:
turn += 1
if counter in arr_2_power:
counter = counter // 2
else:
for i in range(1, 65):
if arr_2_power[i] > counter:
counter -= arr_2_power[i - 1]
break
if turn % 2 == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def ans(n):
p = 1
while n > p:
p <<= 1
p >>= 1
return n - p
z = int
a = input
p = print
t = z(a())
while t:
t -= 1
c = 0
n = z(a())
while n > 1:
p = n & n - 1
if p == 0:
n >>= 1
else:
n = ans(n)
c += 1
if c % 2 == 0:
print("Richard")
else:
print("Louise")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def solve(N):
c0 = 0
while N > 0 and not N & 1:
c0 += 1
N >>= 1
c1 = 0
while N > 0:
if N & 1:
c1 += 1
N >>= 1
if (c0 + c1) % 2 == 0:
return "Louise"
else:
return "Richard"
T = int(input())
for _ in range(T):
N = int(input())
print(solve(N))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for i in range(T):
N = int(input())
bits = list(bin(N))[2:]
p = ["Louise", "Richard"]
bit_count = bits.count("1")
right_zeros = bits[::-1].index("1")
print(p[(bit_count + right_zeros) % 2])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def isp2(val):
if not val % 2 == 0:
return 0
if val == 2:
return 1
while val > 0:
val = val / 2
if val == 2:
return 1
return 0
def findPower(previous, goal):
if previous * 2 > goal:
return previous
else:
return findPower(previous * 2, goal)
testcases = int(input())
for _ in range(testcases):
counter = int(input())
turns = 1
while not counter == 1:
if isp2(counter) == 1:
counter = counter / 2
else:
counter -= findPower(1, counter)
turns += 1
if turns % 2 == 0:
print("Louise")
else:
print("Richard")
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for t in range(int(input())):
v = bin(int(input()))
names = ["Richard", "Louise"]
v = list(map(int, v[2:]))
count = 0
while True:
i1 = v.index(1)
if sum(v) == 1 and i1 == len(v) - 1:
break
if sum(v) == 1:
for i in range(i1, len(v)):
v[i] = 1
v[v.index(1)] = 0
count += 1
print(names[count % 2])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
import sys
def run_tests():
T = sys.stdin.readline()
for i in range(int(T)):
determine_winner(int(sys.stdin.readline()))
def determine_winner(N):
lastMoveLouise = False
while N != 1:
if N & N - 1 == 0:
N >>= 1
else:
N -= 1 << get_highest_bit_position(N) - 1
lastMoveLouise = not lastMoveLouise
winner = "Louise" if lastMoveLouise else "Richard"
sys.stdout.write(winner + "\n")
def get_highest_bit_position(n):
counter = 0
while n != 0:
counter += 1
n >>= 1
return counter
run_tests()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def butt(n):
i = 0
c = 0
h = 0
while n:
if n & 1:
c += 1
h = i
n >>= 1
i += 1
return c, h
T = int(input())
for _ in range(T):
N = int(input())
c = 0
dudes = ["Richard", "Louise"]
while N > 1:
num_bits, highest_bit = butt(N)
if num_bits == 1:
N >>= 1
else:
N -= 2**highest_bit
c += 1
print(dudes[c % 2])
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
tests = int(input())
for _ in range(tests):
n = int(input())
iterations = 0
while n > 1:
iterations += 1
n = n >> 1 if not n & n - 1 else n - 2 ** (n.bit_length() - 1)
print("Richard" if not iterations & 1 else "Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def solve(n):
powersOfTwo = set()
for x in range(64):
powersOfTwo.add(1 << x)
steps = 0
while n > 1:
steps += 1
if not n in powersOfTwo:
largestPower = 1
currentPower = 1
t = n
while t > 0:
if t & 1:
largestPower = currentPower
t >>= 1
currentPower <<= 1
n = n - largestPower
else:
n >>= 1
return "Louise" if steps % 2 == 1 else "Richard"
t = int(input())
for i in range(0, t):
n = int(input())
print(solve(n))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def findFirstOneFromLeft(N):
for i in range(63, -1, -1):
if N >> i & 1 == 1:
return i
def play(N):
i = findFirstOneFromLeft(N)
if N == 1 << i:
return N >> 1
else:
return N & ~(1 << i)
def win(N):
flag = 1
while N != 1:
N = play(N)
flag = 1 - flag
if flag:
print("Richard")
else:
print("Louise")
T = int(input())
for _ in range(T):
win(int(input()))
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for _ in range(int(input())):
a = int(input())
c = 1
while a & 1 == 0:
c ^= 1
a >>= 1
while a:
if a & 1:
c ^= 1
a >>= 1
print("Louise" if c else "Richard")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
for case in range(t):
n = int(input())
count = 1
while n > 1:
count += 1
if n & n - 1 == 0:
n >>= 1
else:
n -= int("1" + "0" * len(bin(n)[3:]), 2)
if count % 2 == 0:
print("Louise")
else:
print("Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def CountMoves(N):
C = 0
while N > 1 and N % 2 == 0:
N = N // 2
C = C + 1
while N > 1:
r = N % 2
if r == 1:
C = C + 1
N = (N - r) // 2
return C
T = int(input())
while T:
T = T - 1
N = int(input())
Moves = CountMoves(N)
if Moves % 2 == 0:
print("Richard")
else:
print("Louise")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def is_power_of_two(n):
return n & n - 1 == 0 and n > 0
def largest_power(n):
res = 1
while res < n:
res <<= 1
return res >> 1
def whois_winner(n):
winner = 0
while n != 1:
if is_power_of_two(n):
n >>= 1
winner ^= 1
else:
n -= largest_power(n)
winner ^= 1
return "Louise" if winner else "Richard"
def main():
t = int(input())
for x in range(t):
print(whois_winner(int(input())))
main()
|
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
class Game(object):
def __init__(self, initialvalue):
self.counter = initialvalue
self.turn = "Richard"
def play(self):
while not self.winner:
if self._pow2(self.counter):
self.reduce_by_half()
else:
self.reduce_by_pow2()
return self.winner
def reduce_by_half(self):
self.flip()
self.counter = self.counter >> 1
def reduce_by_pow2(self):
self.flip()
self.counter -= 1 << self._hiset(self.counter)
@property
def winner(self):
if self.counter == 1:
return self.turn
else:
return False
def flip(self):
if self.turn == "Louise":
self.turn = "Richard"
else:
self.turn = "Louise"
def _pow2(self, a):
return a != 1 and a & a - 1 == 0
def _testbit(self, a, bit):
return a & 1 << bit != 0
def _hiset(self, a):
bit = int.bit_length(a)
while not self._testbit(a, bit):
bit -= 1
return bit
def main():
testcount = int(input())
while testcount > 0:
game = Game(int(input()))
print(game.play())
testcount -= 1
main()
|
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING FUNC_DEF WHILE VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN NUMBER VAR FUNC_DEF IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF RETURN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for t in range(int(input())):
n, z = int(input()), False
while n > 1:
if n & n - 1 == 0:
n = n >> 1
else:
t, c = n, 0
while t > 0:
t, c = t >> 1, c + 1
n = n - (1 << c - 1)
z = not z
if z:
print("Louise ")
else:
print("Richard ")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def get(n):
x = 1
while x * 2 < n:
x *= 2
return x
T = int(input())
for t in range(T):
n = int(input())
for i in range(1000):
n -= get(n)
if n == 1:
if i % 2 == 0:
print("Louise")
else:
print("Richard")
break
|
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for i in range(0, int(input())):
rWins = True
num = int(input())
while num != 1:
if num & num - 1 == 0:
if (len(bin(num)) - 3) % 2 == 0:
break
else:
rWins = not rWins
break
else:
rWins = not rWins
num -= int(2 ** (len(bin(num)) - 3))
if rWins:
print("Richard")
else:
print("Louise")
|
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
n = int(input())
for i in range(n):
turns = 0
x = bin(int(input()))
if False:
print("Richard")
else:
turns += x.count("1") - 1
turns += len(x.split("1")[-1])
print("Louise" if turns % 2 == 1 else "Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER EXPR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def solve(x):
ret = False
ii = True
for j in bin(x)[:1:-1]:
if j == "0":
if ii:
ret ^= True
else:
ii = False
ret ^= True
return ret
T = int(input())
for i in range(T):
print("Richard" if solve(int(input())) else "Louise")
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for t in range(int(input())):
n = int(input())
b = bin(n)
i = b.count("1")
j = len(b.split("1")[-1])
if (i + j) % 2 == 0:
print("Louise")
else:
print("Richard")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def is_power_of_two(n):
return n != 0 and n & n - 1 == 0
def highest_power_of_two(n):
n = n | n >> 1
n = n | n >> 2
n = n | n >> 4
n = n | n >> 8
n = n | n >> 16
return n - (n >> 1)
t = int(input())
for i in range(t):
n = int(input())
louise = True
while n != 1:
if is_power_of_two(n):
n = n // 2
else:
n -= highest_power_of_two(n)
louise = not louise
if louise:
print("Richard")
else:
print("Louise")
|
FUNC_DEF RETURN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for _ in range(int(input())):
num = int(input())
turns = 0
while num != 1:
low = 1
while low * 2 <= num:
low *= 2
if low == num:
num = num // 2
else:
num -= low
turns += 1
print("Richard" if turns % 2 == 0 else "Louise")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for i in range(T):
N = int(input())
n = 0
while N > 1:
count = bin(N).count("1")
if count == 1:
N = int(N / 2)
else:
N = N - pow(2, len(bin(N)) - 3)
n = (n + 1) % 2
if n == 0:
print("Richard")
else:
print("Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def makeMove(n):
if n <= 1:
return None
nb = n
i, ones = 0, 0
while nb > 0:
if nb & 1:
ones += 1
i += 1
nb >>= 1
if ones > 1:
return n - (1 << i - 1)
else:
return n >> 1
def playBall(n):
rounds = 0
while n:
n = makeMove(n)
if n:
rounds += 1
if rounds % 2:
return "Louise"
else:
return "Richard"
tcs = int(input().strip())
for i in range(0, tcs):
print(playBall(int(input().strip())))
|
FUNC_DEF IF VAR NUMBER RETURN NONE ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def counter():
T = int(input())
for t in range(0, T):
N = int(input())
binN = "{0:b}".format(N)
lenBinN = len(binN)
if binN.count("1") == 1:
if lenBinN % 2 == 0:
print("Louise")
else:
print("Richard")
else:
flag = True
while 1:
binN = binN[1:]
binN = binN[binN.find("1") :]
flag = not flag
lenBinN = len("{0:b}".format(int(binN, 2)))
if binN.count("1") == 1:
if flag:
if lenBinN % 2 == 0:
print("Louise")
else:
print("Richard")
elif lenBinN % 2 == 0:
print("Richard")
else:
print("Louise")
break
N = int(binN, 2)
counter()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER IF VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for test in range(int(input())):
N = int(input())
c = 0
while N > 1:
b = bin(N)[2:]
if b[1:].count("1"):
N = int(b[1:], 2)
else:
N >>= 1
c += 1
print("Louise" if c % 2 else "Richard")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def toBin(n):
temp = n
t = ""
top = 0
count = 0
index = 0
while n > 0:
if n & 1 == 1:
top = index
count = count + 1
n >>= 1
index = index + 1
if count == 1:
return temp - int(temp / 2)
return temp - (1 << top)
amount = int(input())
for i in range(0, amount):
n = int(input())
c = 0
while n != 1:
n = toBin(n)
c = c + 1
if c % 2 == 0:
print("Richard")
else:
print("Louise")
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
for t in range(int(input())):
turn = True
n = int(input())
powers_of_2 = [
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8192,
16384,
32768,
65536,
131072,
262144,
524288,
1048576,
2097152,
4194304,
8388608,
16777216,
33554432,
67108864,
134217728,
268435456,
536870912,
1073741824,
2147483648,
4294967296,
8589934592,
17179869184,
34359738368,
68719476736,
137438953472,
274877906944,
549755813888,
1099511627776,
2199023255552,
4398046511104,
8796093022208,
17592186044416,
35184372088832,
70368744177664,
140737488355328,
281474976710656,
562949953421312,
1125899906842624,
2251799813685248,
4503599627370496,
9007199254740992,
18014398509481984,
36028797018963968,
72057594037927936,
144115188075855872,
288230376151711744,
576460752303423488,
1152921504606846976,
2305843009213693952,
4611686018427387904,
9223372036854775808,
18446744073709551616,
]
while n != 1:
if n in powers_of_2:
n /= 2
turn = not turn
else:
turn = not turn
for i in range(len(powers_of_2)):
if n <= powers_of_2[i]:
n -= powers_of_2[i - 1]
break
if n == 1:
if turn:
print("Richard")
else:
print("Louise")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def is_power_of_2(n):
return n & n - 1 == 0
def largest_p2_less(n):
b = 1
while b < n:
b <<= 1
return b >> 1
t = int(input())
for i in range(t):
turn = 0
n = int(input())
c = n
if c == 1:
print("Richard")
else:
while c != 1:
if is_power_of_2(int(c)):
c /= 2
else:
c -= largest_p2_less(c)
turn ^= 1
if turn == 0:
print("Richard")
else:
print("Louise")
|
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def counterGame(n):
fs = bin(n)[2:]
total = 0
i = len(fs) - 1
while i != -1:
if fs[i] != "0":
break
i -= 1
total += len(fs) - i - 1 + fs[:i].count("1")
if total & 1:
print("Louise")
else:
print("Richard")
def main():
t = int(input())
while t != 0:
n = int(input())
counterGame(n)
t -= 1
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def pow3(a):
z = 1
while 2 * z < a:
z *= 2
return z
r = int(input(""))
for g in range(r):
turn = "Louise"
x = int(input(""))
z = x
while True:
if z == 1:
if turn == "Louise":
print("Richard")
break
else:
print("Louise")
break
z -= pow3(z)
if turn == "Louise":
turn = "Richard"
else:
turn = "Louise"
|
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
for i in range(t):
val = int(input())
bin_string = bin(val)[2:]
if val == 1:
print("Richard")
continue
moves = 0
while True:
bin_len = len(bin_string)
num_zeros = sum(1 for val in bin_string if val == "0")
if num_zeros == bin_len - 1:
if (moves + bin_len) % 2 == 1:
print("Richard")
else:
print("Louise")
break
else:
bin_string = bin_string[1:]
bin_string = bin_string.lstrip("0")
moves += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
while t > 0:
t = t - 1
n = int(input())
m = 0
while n > 1:
i = 0
k = 0
while n >> i > 0:
k = k + (n >> i & 1)
i = i + 1
if k == 1:
n = n >> 1
else:
n = n - (1 << i - 1)
m = m + 1
if m == 0 or m & 1 == 1:
print("Louise")
else:
print("Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def f(x):
if x == 1:
return False
if x & x - 1 == 0:
return not f(x >> 1)
else:
return not f(int(bin(x)[3:], 2))
t = int(input())
for _ in range(t):
print("Louise" if f(int(input())) else "Richard")
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def cntAlt(n):
c = 0
while n != 1:
t = 1
while t < n:
t <<= 1
n -= t >> 1
c += 1
return c
for i in range(int(input())):
print("Richard" if cntAlt(int(input())) % 2 == 0 else "Louise")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER STRING STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def update_n(n):
pow_2 = 1 << n.bit_length() - 1
if n == pow_2:
return n // 2
else:
return n - pow_2
def solve(n):
louise_turn = True
while n > 1:
n = update_n(n)
louise_turn = not louise_turn
return "Richard" if louise_turn else "Louise"
for _ in range(int(input())):
n = int(input())
print(solve(n))
|
FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def get_winner(num):
binary = bin(num)[2:]
num_ones = binary.count("1")
num_trailing_zeros = len(binary.split("1")[-1])
num_turns = num_ones - 1 + num_trailing_zeros
if num_turns % 2 == 1:
return "Louise"
else:
return "Richard"
num = int(input())
for counter_i in range(num):
counter = int(input())
print(get_winner(counter))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def one_places(N):
b_str = bin(N)[2:]
return [idx for idx, c in enumerate(reversed(b_str)) if c == "1"]
def game_result(N):
op = one_places(N)
return (len(op) - 1 + op[0]) % 2
_players = "Richard", "Louise"
T = int(input())
for _ in range(T):
N = int(input())
print(_players[game_result(N)])
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
for i in range(t):
n = int(input())
end = n & -n
turns = bin(n - end).count("1") + bin(end).count("0") - 1
print("Richard Louise".split()[turns % 2])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
import sys
t = int(sys.stdin.readline().strip())
for tests in range(t):
n = int(sys.stdin.readline().strip())
turns = 0
while n > 1:
msb = 1 << len(bin(n)) - 3
if msb & n - 1 == 0:
n = n >> 1
else:
n = n - msb
turns += 1
if turns % 2 == 0:
print("Richard")
else:
print("Louise")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
t = int(input())
for _ in range(t):
n = int(input())
res = 0
while n > 1:
if "1" not in str(bin(n))[3:]:
n >>= 1
else:
n -= int("1" + "0" * len(str(bin(n))[3:]), 2)
res += 1
if res % 2:
print("Louise")
else:
print("Richard")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF STRING FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
def testpower(n):
power = False
t = 1
while t < n:
t <<= 1
if t == n:
power = True
return power, t >> 1
T = int(input())
for _ in range(T):
n = int(input())
p = 0
while n ^ 1:
power, below = testpower(n)
if power:
n >>= 1
else:
n -= below
p += 1
if p & 1:
print("Louise")
else:
print("Richard")
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide it by $2$. If not, they reduce it by the next lower number which is a power of $2$. Whoever reduces the number to $1$ wins the game. Louise always starts.
Given an initial value, determine who wins the game.
Example
$n=132$
It's Louise's turn first. She determines that $132$ is not a power of $2$. The next lower power of $2$ is $\textbf{128}$, so she subtracts that from $132$ and passes $4$ to Richard. $4$ is a power of $2$, so Richard divides it by $2$ and passes $2$ to Louise. Likewise, $2$ is a power so she divides it by $2$ and reaches $1$. She wins the game.
Update If they initially set counter to $1$, Richard wins. Louise cannot make a move so she loses.
Function Description
Complete the counterGame function in the editor below.
counterGame has the following parameter(s):
int n: the initial game counter value
Returns
string: either Richard or Louise
Input Format
The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of testcases.
Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$, the initial value for each game.
Constraints
$1\leq t\leq10$
$1\leq n\leq2^{64}-1$
Sample Input 0
1
6
Sample Output 0
Richard
Explanation 0
$\boldsymbol{6}$ is not a power of $2$ so Louise reduces it by the largest power of $2$ less than $\boldsymbol{6}$:$6-4=2$.
$2$ is a power of $2$ so Richard divides by $2$ to get $1$ and wins the game.
|
T = int(input())
for Ti in range(T):
N = int(input())
result = 0
zero = True
while zero:
N, R = divmod(N, 2)
zero = R == 0
if zero:
result += 1
while N > 0:
N, R = divmod(N, 2)
if R == 1:
result += 1
print("Richard" if result % 2 == 0 else "Louise")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING STRING
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
sum1 = 0
x = 0
for i in range(n):
sum1 += l[i]
x ^= l[i]
print(2)
print(x, sum1 + x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def inp(dtype=str, strip=True):
s = input()
res = [dtype(p) for p in s.split()]
res = res[0] if len(res) == 1 and strip else res
return res
def problem3():
t = inp(int)
for _ in range(t):
n = inp(int)
a = inp(int, strip=False)
a_sum = sum(a)
a_xor = a[0]
for el in a[1:]:
a_xor = a_xor ^ el
x = a_xor
b_sum = a_sum + x
y = b_sum
print(2)
print(x, y)
problem3()
|
FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
n = int(input())
l = input().split()
li = [int(i) for i in l]
xori = 0
for i in li:
xori ^= i
sumi = sum(li)
print(3)
print(xori, xori + sumi, 0)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
results = []
for i in range(1, int(input()) + 1):
xorsum = 0
numlens = int(input())
array = input().split()
numbers = [int(x) for x in array]
if numlens == 1:
xorsum = numbers[0]
else:
for i in range(0, numlens):
xorsum = xorsum ^ numbers[i]
if sum(numbers) == xorsum * 2:
results.append("0")
else:
results.append("2")
results.append(str(xorsum) + " " + str(xorsum + sum(numbers)))
for i in results:
print(i)
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
A = list(map(int, input().split()))
Query.append((N, A))
for N, A in Query:
x = 0
s = 0
for a in A:
x ^= a
s += a
t = s % 2 + (1 << 50)
s += t
x ^= t
d = (2 * x - s) // 2
print(3)
print(t, d, d)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
t = int(input())
for q in range(t):
n = int(input())
lst = [int(i) for i in input().split()]
s, xor = sum(lst), lst[0]
for i in range(1, len(lst)):
xor ^= lst[i]
if 2 * xor == s:
print(0)
else:
print(2)
print(xor, s + xor)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
t = int(input())
for I in range(t):
n = int(input())
li = list(map(int, input().split()))
sum1 = 0
x = 0
for pp in li:
num = int(pp)
sum1 += int(num)
x ^= int(num)
print(2)
print(str(x) + " " + str(sum1 + x))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
t = int(input())
def xor(A):
x = 0
for i in range(len(A)):
x = A[i] ^ x
return x
for i in range(t):
n = int(input())
A = list(map(int, input().split()))
x = sum(A)
y = xor(A)
print(2)
print(y, x + y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().strip().split()))
vs = sum(a)
xor = 0
for e in a:
xor = xor ^ e
print(2)
print(xor, vs + xor)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
t = int(input())
while t:
n = int(input())
l = list(map(int, input().split()))
S = sum(l)
X = 0
for i in range(n):
X = X ^ l[i]
temp = []
count = 0
if S == 2 * X:
print(count)
else:
print(2)
temp.append(X)
temp.append(S + X)
print(*temp)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def solve(xr, sm):
k = []
if 2 * xr == sm:
return []
else:
k.append(xr)
k.append(sm + xr)
return k
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
xr = 0
sm = 0
for i in l:
xr = xr ^ i
sm += i
z = solve(xr, sm)
print(len(z))
print(*z)
|
FUNC_DEF ASSIGN VAR LIST IF BIN_OP NUMBER VAR VAR RETURN LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def main():
for t in range(0, int(input())):
n = input()
arr = list(map(int, input().split()))
bin_arr = []
for x in arr:
bin_arr.append(num_bin(x))
xor_sum = bin_arr[0]
add_count = 0
nums_added = []
for x in range(1, len(bin_arr)):
xor_sum = x_or(xor_sum, bin_arr[x])
if bin_num(xor_sum) == sum(arr) / 2:
print("0")
print("")
else:
print("2")
print(bin_num(xor_sum), bin_num(xor_sum) + sum(arr))
def num_bin(num):
el = num
count = 0
count_list = []
while True:
el = el // 2
if el >= 1:
count += 1
continue
count_list.append(count)
if num - 2**count > 0:
num = num - 2**count
el = num
count = 0
continue
else:
break
binary = []
for n in range(0, max(count_list) + 1):
binary.append(0)
for i in count_list:
binary[-(i + 1)] = 1
if num == 0:
binary = [0]
return binary
def bin_num(b):
num = 0
for x in range(0, len(b)):
if b[-(x + 1)] == 1:
num = 2**x + num
return num
def x_or(num1, num2):
new_arr = []
flag = False
diff = len(num2) - len(num1)
if len(num1) >= len(num2):
diff = len(num1) - len(num2)
flag = True
if flag:
for i in range(0, diff):
new_arr.insert(i, num1[i])
for i in range(0, len(num2)):
if num1[i + diff] != num2[i]:
new_arr.append(1)
else:
new_arr.append(0)
else:
for i in range(0, diff):
new_arr.insert(i, num2[i])
for i in range(0, len(num1)):
if num2[i + diff] != num1[i]:
new_arr.append(1)
else:
new_arr.append(0)
return new_arr
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def xor(s):
ans = 0
for i in s:
ans ^= i
return ans
T = int(input())
for case in range(T):
n = int(input())
s = list(map(int, input().split()))
a = sum(s)
b = xor(s)
if a == 2 * b:
ans = []
else:
ans = [b, a + b]
print(len(ans))
print(*ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
import sys
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().rstrip().split()))
x = []
xor = 0
s = 0
for j in range(n):
xor = xor ^ arr[j]
s = s + arr[j]
if 2 * xor == s:
print("0")
print("")
else:
print("2")
print(str(xor) + " " + str(s + xor))
sys.stdout.flush()
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def solve():
n = int(input())
arr = [int(x) for x in input().split()]
xor = 0
for x in arr:
xor ^= x
arr.append(xor)
sm = sum(arr)
arr.append(sm)
print(2)
print(xor, sm)
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
res = sum(a)
xor = a[0]
ans = []
for i in range(1, n):
xor ^= a[i]
if res == 2 * xor:
print(0)
print("")
else:
ans.append(xor)
ans.append(res + xor)
print(len(ans))
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
from sys import stdin
def rl():
return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
(n,) = rl()
a = rl()
x = y = 0
for ai in a:
x += ai
y ^= ai
print(2)
print(y, x + y)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$.
You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output two lines.
In the first line, output a single integer $s$ ($0\le s\le 3$)Β β the number of elements you want to append.
In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β the elements you want to append to the array.
If there are different solutions, you are allowed to output any of them.
-----Example-----
Input
3
4
1 2 3 6
1
8
2
1 1
Output
0
2
4 4
3
2 6 2
-----Note-----
In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied.
In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
|
def main():
answer = ""
for test in range(int(input())):
n = int(input())
array = list(map(int, input().split(" ")))
xor = 0
for num in array:
xor = xor ^ num
summ = sum(array)
if summ % 2 == 0:
firstelement = 288230376151711744
else:
firstelement = 288230376151711745
xor = xor ^ firstelement
checkxor = xor
summ += firstelement
sec_and_third_element = (xor * 2 - summ) // 2
answer += (
"3 \n"
+ str(firstelement)
+ " "
+ str(sec_and_third_element)
+ " "
+ str(sec_and_third_element)
+ "\n"
)
print(answer)
main()
|
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.