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 1 of 2
mx=0;
for a=-1000:1000
  for b=-1000:1000
    pset=[];
    for n=0:9999999
      v=n^2+a*n+b;
      if v<0
        break
      end
      if ~isprime(v)
        break
      end
      pset(end+1)=v;
    end
    if length(pset)>mx
      disp([length(pset) a b])
      mx=length([pset]);
    end
  end
end

a=-61; b= 971;
    for n=0:9999999
      v=n^2+a*n+b;
      if v<0
        break
      end
      if ~isprime(v)
        break
      end
      fprintf('%3d %5d ',n, v)
    end





largest #
 so far
          a     b
     1 -1000     2
     2  -996   997
     3  -499   997
     4  -325   977
     5  -245   977
     6  -197   983
     7  -163   983
     8  -131   941
     9  -121   947
    11  -105   967
    71   -61   971
    
 For a=-61 b= 971: 
  
  n  prime
     value
  
  0   971
  1   911
  2   853
  3   797
  4   743
  5   691
  6   641
  7   593
  8   547
  9   503
 10   461
 11   421
 12   383
 13   347
 14   313
 15   281
 16   251
 17   223
 18   197
 19   173
 20   151
 21   131
 22   113
 23    97
 24    83
 25    71
 26    61
 27    53
 28    47
 29    43
 30    41
 31    41
 32    43
 33    47
 34    53
 35    61
 36    71
 37    83
 38    97
 39   113
 40   131
 41   151
 42   173
 43   197
 44   223
 45   251
 46   281
 47   313
 48   347
 49   383
 50   421
 51   461
 52   503
 53   547
 54   593
 55   641
 56   691
 57   743
 58   797
 59   853
 60   911
 61   971
 62  1033
 63  1097
 64  1163
 65  1231
 66  1301
 67  1373
 68  1447
 69  1523
 70  1601

Edited on February 7, 2024, 3:43 pm
  Posted by Charlie on 2024-02-07 14:34:58

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
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