Adopted new convention from template
This commit is contained in:
parent
6c6f2a2b4f
commit
273aeea7f8
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Created on 15 Sep 2019
|
||||
|
||||
@ -9,7 +9,7 @@ Solution for problem 27 of Project Euler
|
||||
https://projecteuler.net/problem=27
|
||||
"""
|
||||
|
||||
from utils import timeit, is_prime
|
||||
from utils import is_prime, timeit
|
||||
|
||||
|
||||
@timeit("Problem 27")
|
||||
@ -24,35 +24,36 @@ def compute():
|
||||
divisible by 41, and certainly when n=41,41^2+41+41 is clearly divisible
|
||||
by 41.
|
||||
|
||||
The incredible formula n^2−79n+1601 was discovered, which produces 80
|
||||
The incredible formula n^2-79n+1601 was discovered, which produces 80
|
||||
primes for the consecutive values 0≤n≤79. The product of the coefficients,
|
||||
−79 and 1601, is −126479.
|
||||
-79 and 1601, is -126479.
|
||||
|
||||
Considering quadratics of the form:
|
||||
|
||||
n^2 + an + b
|
||||
|
||||
where |a|<1000, |b|≤1000 and |n| is the modulus/absolute value of n
|
||||
e.g. |11|=11 and |−4|=4
|
||||
e.g. |11|=11 and |-4|=4
|
||||
|
||||
Find the product of the coefficients, a and b, for the quadratic expression
|
||||
that produces the maximum number of primes for consecutive values of n,
|
||||
starting with n=0.
|
||||
"""
|
||||
LIMIT = 1000
|
||||
|
||||
limit = 1000
|
||||
consecutive_values = 0
|
||||
|
||||
for a in range(-999, LIMIT):
|
||||
for b in range(LIMIT + 1):
|
||||
for a in range(-999, limit):
|
||||
for b in range(limit + 1):
|
||||
n = 0
|
||||
while is_prime(abs((n ** 2) + (a * n) + b)):
|
||||
while is_prime(abs((n**2) + (a * n) + b)):
|
||||
n += 1
|
||||
if n > consecutive_values:
|
||||
consecutive_values = n
|
||||
c = a * b
|
||||
return c
|
||||
ans = a * b
|
||||
|
||||
return ans
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(f"Result for Problem 27: {compute()}")
|
||||
print(f"Result for Problem 27 is {compute()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user