We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My Code Works At Python Pass all test casses. check this out !
import os
import sys
import math
Complete the towerBreakers function below.
def towerBreakers(arr):
d = 0
for x in arr:
d ^= primeFactors(x)
if d != 0:
return 1
else:
return 2
def primeFactors(n):
count = 0
flag = True
while n % 2 == 0:
if flag:
count += 1
flag = False
n //= 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
count += 1
n //= i
if n > 2:
count += 1
return count
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
arr_count = int(input())
arr = list(map(int, input().rstrip().split()))
result = towerBreakers(arr)
fptr.write(str(result) + '\n')
fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tower Breakers, Again!
You are viewing a single comment's thread. Return to all comments →
My Code Works At Python Pass all test casses. check this out !
import os import sys import math
Complete the towerBreakers function below.
def towerBreakers(arr): d = 0 for x in arr: d ^= primeFactors(x) if d != 0: return 1 else: return 2
def primeFactors(n): count = 0 flag = True while n % 2 == 0: if flag: count += 1 flag = False n //= 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: count += 1 n //= i if n > 2: count += 1 return count
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')