Project Euler Problem#27

#python program to find the product of co-efficient in quadratic formula whih give max number of primes
def is_prime(n):
    if n <= 1 or n % 2 == 0:
        return False
    if n == 2:
        return True
    for i in range(3, int(n**(0.5) + 1), 2):
        if n % i == 0:
            return False
    return True
max_n,num1,num2= 0,0,0
for i in range(1,1001):
    if is_prime(i): 
        for j in range(1,1001):
            for k in range(0,1000):
                a=(k*k)+(j*k)+(i)
                if not is_prime(a):
                    if k>max:
                        max_n,num1,num2= k,j,i
                    break
            for k in range(0,1000):
                a=(k*k)+(j*k)-(i)
                if not is_prime(a):
                    if k>max:
                        max_n,num1,num2= k,j,i
                    break
            for k in range(0,1000):
                a=(k*k)-(j*k)-(i)
                if not is_prime(a):
                    if k>max:
                        max_n,num1,num2= k,j,i
                    break
            for k in range(0,1000):
                a=(k*k)-(j*k)+(i)
                if not is_prime(a):
                    if k>max:
                        max_n,num1,num2= k,j,i
                    break
print(num1*num2)  #-59231
0
Subscribe to my newsletter

Read articles from Varjinth subramaniyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Varjinth subramaniyan
Varjinth subramaniyan