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.
defprimeCount(n):ifn<2:return0primes=[]candidate=2product=1count=0# We need to find the product of consecutive primes <=nwhileTrue:# Check if candidate is primeis_prime=Trueforpinprimes:ifp*p>candidate:breakifcandidate%p==0:is_prime=Falsebreakifis_prime:ifproduct*candidate>n:breakproduct*=candidatecount+=1primes.append(candidate)candidate+=1returncount# Read input and process queriesif__name__=="__main__":q=int(sys.stdin.readline())for_inrange(q):n=int(sys.stdin.readline())print(primeCount(n))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Leonardo's Prime Factors
You are viewing a single comment's thread. Return to all comments →
THIS CODE WORKSSS.. EASYYY PEASYYY