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.
a little messy but solves all the testcases 100/-points python3
importitertoolsdefisprime(x):ifx%2==0:returnFalseforiinrange(3,int(x**0.5)+1,2):ifx%i==0:returnFalsereturnTruen=int(input())max_consec=0solutions=[]foriinitertools.product(list(range(-n,n+1,1)),range(n+1)):#I didn't set the range of b through the negatives because for x=0 the exspression will become b which must be positive so only +values primes=0x=0whileTrue:abc=x**2+i[0]*x+i[1]ifabc<0:#as our required number must be atleast positivebreakifnotisprime(abc):breakx+=1primes+=1ifprimes>max_consec:solutions.append(i)max_consec=primesprint(*solutions[-1])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #27: Quadratic primes
You are viewing a single comment's thread. Return to all comments →
a little messy but solves all the testcases
100/-points python3