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.
importmathimportsysn=int(sys.stdin.readline())numbers=map(int,sys.stdin.readline().split())witnesses=[2,3,5,7,11,13,17,19,23,29]Primes=[]IsPrime=[True]*100001forpinrange(2,100000):ifnot(IsPrime[p]):continuePrimes.append(p)mult=p*pwhilemult<100001:IsPrime[mult]=Falsemult+=pdefGetRidOf2(n):whilen%2==0:n//= 2returnndefIsComposite(n,a,s,d):ifpow(a,d,n)==1:returnFalseforrinrange(s):ifpow(a,(1<<r)*d,n)==n-1:returnFalsereturnTruedefIsPrime(n):s=0d=n-1whiled%2==0:d>>=1s+=1forainwitnesses:ifIsComposite(n,a,s,d):returnFalsereturnTruedefIsNPowerOfPrime(n):ifIsPrime(n):returnTruesqrt=int(math.sqrt(n))ifsqrt*sqrt==nandIsPrime(n):returnTruereturnFalsedefIsNSquare(n):sqrt=int(math.sqrt(n))return(sqrt*sqrt==n)defFactor(n):nbFactors=0sumFactors=0ifn%2==0:nbFactors+=1n=GetRidOf2(n)ifIsNSquare(n):sumFactors=1n=int(math.sqrt(n))forprimeinPrimes:ifn==1:breakifn%prime!=0:continuenbFactors+=1n//= primewhilen%prime==0:n//= prime ifn==1:return(nbFactors,sumFactors)ifIsNPowerOfPrime(n):return(nbFactors+1,sumFactors)return(nbFactors+2,sumFactors)result=[[0,0],[0,0]]forninnumbers:(nb,s)=Factor(n)result[nb%2][s]+=1finalResult=result[0][0]+result[0][1]finalResult=max(finalResult,result[0][0]+result[1][0])finalResult=max(finalResult,result[1][1]+result[1][0])finalResult=max(finalResult,result[1][1]+result[0][1])print(finalResult)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nice Clique
You are viewing a single comment's thread. Return to all comments →
Python3 solution