All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Quadratic Primes (Posted on 2024-02-07) Difficulty: 3 of 5
Consider the quadratic: n^2 + an + b. Consider integer coefficients a and b in the range: |a|< 1000, |b| ≤ 1000. For what values of a and b will the expression produce the maximum number of primes for consecutive values of n, starting with n=0? (Project Euler problem 27)

See The Solution Submitted by Steven Lord    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer Solution Comment 2 of 2 |
Since  f(0) must be prime, b must be prime and therefore positive.

note that since n=0 is included, the number of consecutive primes generated is n+1

 n    a    b   f(n)
 1  -996  997  2
 2  -499  997  3
 3  -325  977  11
 4  -245  977  13
 5  -197  983  23
 6  -163  983  41
 7  -131  941  73
 8  -121  947  43
10  -105  967  17
70   -61  971  1601  <-- solution
(a,b) = (-61,  971)   71 consecutive primes

When the limit is raised from 1000 to 2000, a consecutive run of 80 primes exists.
 n    a    b   f(n)
79  -79  1601  1601

----------------
big = 1000
primes = [n for n in range(100000) if isprime(n)]
primesUnder1000 = [n for n in range(big) if isprime(n)]

best = [0,0,0]
for a in range(-big,big):
    for b in primesUnder1000:
        temp = [0,a,b,0]
        for n in range(200):
            f = n**2 + a*n + b
            if f in primes:
                temp[0] = n
                temp[3] = f
            else:
                if temp[0] > best[0]:
                    best = temp
                    print(best)
                break

  Posted by Larry on 2024-02-08 11:16:46
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (15)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information