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.
...fromfunctoolsimportreducefromoperatorimportxor## Obviously this becomes standard nim, # when we look at the prime factor count for each number#deftowerBreakers(arr):arr=map(factorcount,arr)return1ifreduce(xor,arr)else2PRIMES=Nonedeffactorcount(n:int)->int:ifnotPRIMES:init_primes()prime_it=iter(PRIMES)result=0while...:p=next(prime_it)ifp*p>n:breakwhilen%p==0:result+=1n//=pifn>1:result+=1returnresultdefinit_primes():globalPRIMESPRIMES=[2,3,5,7]forpinrange(10,1100):iffactorcount(p)==1:PRIMES.append(p)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tower Breakers, Revisited!
You are viewing a single comment's thread. Return to all comments →
Just another Python solution ...