-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathsolution.py
44 lines (35 loc) · 979 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def nim_sum(a,n):
ans = 0
for i in range(n):
ans = ans^a[i]
return ans
# input number of testcases
t = int(input())
while(t != 0):
t -= 1
# input number of towers
n = int(input())
# input height of each tower
a= [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in range(n):
if(a[i] == 1):
b[i] = 0
else:
b[i] = 0
j = 2
root = int(pow(a[i],0.5))
while(a[i] != 1 and j<=root):
if(a[i]%j == 0):
while(a[i]%j == 0):
b[i] += 1
a[i] = a[i]//j
j += 1
if(a[i] != 1):
b[i] += 1
ans = nim_sum(b, n)
# for each test case print an integer denoting to a winner
if(ans != 0):
print("1")
else:
print("2")