MathomalyA field guide to patterns, proofs and open questions

ExplorationsWhy 41 is lucky, and what 163 has to do with it

The Formula That Keeps Making Primes

Known as Euler’s prime-generating polynomial

Exhaustively checkedprimesquadratic polynomialsclass numberintermediate

Work out n² + n + 41 for n = 0 and you get 41. Increase n by 1 each time and you get 43, 47, 53, 61, and every value you try is for a long, unbroken run. The run has a hard end that no choice of the constant 41 could avoid, and 41 is the last of only six constants that reach it: 2, 3, 5, 11, 17 and 41. The reason is a fact about the number 163 = 4 × 41 − 1, and the same fact makes e^(√163) fall astonishingly close to a whole number.

Interactive laboratory

Current view: The run

Watch each value of n² + n + q get a primality verdict, from n = 0 on.

The runn² + n + 41
Play the figure
  1. n = 00² + 0 + 41 = 41prime
  2. n = 11² + 1 + 41 = 43prime
  3. n = 22² + 2 + 41 = 47prime
  4. n = 33² + 3 + 41 = 53prime
  5. n = 44² + 4 + 41 = 61prime
  6. n = 55² + 5 + 41 = 71prime
  7. n = 66² + 6 + 41 = 83prime
  8. n = 77² + 7 + 41 = 97prime
  9. n = 88² + 8 + 41 = 113prime
  10. n = 99² + 9 + 41 = 131prime
  11. n = 1010² + 10 + 41 = 151prime
  12. n = 1111² + 11 + 41 = 173prime
  13. n = 1212² + 12 + 41 = 197prime
  14. n = 1313² + 13 + 41 = 223prime
  15. n = 1414² + 14 + 41 = 251prime
  16. n = 1515² + 15 + 41 = 281prime
  17. n = 1616² + 16 + 41 = 313prime
  18. n = 1717² + 17 + 41 = 347prime
  19. n = 1818² + 18 + 41 = 383prime
  20. n = 1919² + 19 + 41 = 421prime
  21. n = 2020² + 20 + 41 = 461prime
  22. n = 2121² + 21 + 41 = 503prime
  23. n = 2222² + 22 + 41 = 547prime
  24. n = 2323² + 23 + 41 = 593prime
  25. n = 2424² + 24 + 41 = 641prime
  26. n = 2525² + 25 + 41 = 691prime
  27. n = 2626² + 26 + 41 = 743prime
  28. n = 2727² + 27 + 41 = 797prime
  29. n = 2828² + 28 + 41 = 853prime
  30. n = 2929² + 29 + 41 = 911prime
  31. n = 3030² + 30 + 41 = 971prime
  32. n = 3131² + 31 + 41 = 1,033prime
  33. n = 3232² + 32 + 41 = 1,097prime
  34. n = 3333² + 33 + 41 = 1,163prime
  35. n = 3434² + 34 + 41 = 1,231prime
  36. n = 3535² + 35 + 41 = 1,301prime
  37. n = 3636² + 36 + 41 = 1,373prime
  38. n = 3737² + 37 + 41 = 1,447prime
  39. n = 3838² + 38 + 41 = 1,523prime
  40. n = 3939² + 39 + 41 = 1,601prime
  41. n = 4040² + 40 + 41 = 1,68141 × 41, not prime

All 40 values from n = 0 to n = 39 are prime, and n = 40 gives 1,681 = 41 × 41. No q can do better, because n = q − 1 always gives q × q.

Every value, as a table
nValuePrime
041yes
143yes
247yes
353yes
461yes
571yes
683yes
797yes
8113yes
9131yes
10151yes
11173yes
12197yes
13223yes
14251yes
15281yes
16313yes
17347yes
18383yes
19421yes
20461yes
21503yes
22547yes
23593yes
24641yes
25691yes
26743yes
27797yes
28853yes
29911yes
30971yes
311,033yes
321,097yes
331,163yes
341,231yes
351,301yes
361,373yes
371,447yes
381,523yes
391,601yes
401,681no, 41 divides it
a row
one value of n² + n + q, divided by every whole number up to its square root
prime
no divisor was found, so the value is prime
the break
the first value with a divisor, shown with its smallest factor

One row per value of n. A row prints the sum and, when it is not prime, its smallest prime factor beside it. The run ends at the first row with a factor, and that row is the last one the figure draws.

All 40 values from n = 0 to n = 39 are prime, and n = 40 gives 1,681 = 41 × 41. No q can do better, because n = q − 1 always gives q × q.

q
41
Primes in a row
40
Lucky constant
yes

Things to try

Things to try with this figure
  • nines
  • What breaks it. n² + n + q is prime for every n from 0 to q − 2, for any prime q. Try: q = 43, the next prime after 41. The second value, n = 1, is 45, which is 5 × 9.

  • The run for q = 41 ends at n = 40. Without testing it for primality, why is n = 40 certain to fail, and why does the same happen at n = q − 1 for every q?

    Hint

    Put n = q − 1 into n² + n + q and simplify.

  • Try the constants from 2 to 60 one at a time. Which of them reach the longest possible run, and what do you notice about how rare they are?

    Hint

    A run of q − 1 is the longest any q can have. The lucky constants are 2, 3, 5, 11, 17 and 41.

How this page is laid out

Which constant

Forty primes in a row. The last lucky constant, and the reason for this page.

Step by step

Speed sets how fast Run reveals the values.

Speed
Advanced parameters

Cases worth seeing

What is going on

Each explanation begins with a worked example and follows the same operation through intuition, formal statements and proofs. Later sections distinguish what is established from questions that remain open, so you can follow the level of detail useful to you.

Worked by handThe first two values of n² + n + 41, the fortieth, and the forty-first.
  1. n = 00² + 0 + 41 = 4141 is primeNothing from 2 to 6 divides 41, and 7 × 7 is already more than 41.
  2. n = 11² + 1 + 41 = 4343 is primeNothing from 2 to 6 divides 43, so the second value survives too.
  3. n = 3939² + 39 + 41 = 1,6011,601 is primeThe fortieth value. No whole number from 2 to 40 divides it.
  4. n = 4040² + 40 + 41 = 1,68141 × 411,681 = 41², so the run of ends. This was always going to happen at n = 40: for any q, n = q − 1 gives exactly q × q.
The run view in the laboratory prints these same sums, one row per value of n, and divides each by every whole number up to its .
Forty values in a row are , and the forty-first is a , 41 × 41. That square was never a coincidence: it is forced, for every constant, by one line of algebra.
01

What you are seeing

Square a number, add the number, add 41

Take a whole number starting from 0. Square it, add itself, then add 41. For that gives 41, for it gives 43, and for it gives 47. Each of those is , meaning nothing except 1 and itself divides it.

For any constant in place of 41, Mathomaly checks each result by dividing the value by every whole number from 2 up to its , because a larger than the square root would have to be paired with a smaller one. If none divides, the value is and the next row appears. The first row where something divides is the end of the run, and the row prints the smallest factor so you can check it by hand.

02

Why it starts to make sense

Forty in a row is a lot, and it is not a

For the first forty values, to , are all . noticed this in the eighteenth century, and a run that long is hard to wave away: the values reach 1,601, and about one number in seven near that size is prime.

Try other constants in the laboratory and the picture sharpens. Most constants fail at once: , the next , gives 45 for . A handful last longer, and exactly six reach the longest run possible, which has terms: and . Of those six constants, 41 gives the longest run: forty prime values.

03

The key idea

The run has to stop, and only a special constant gets that far

The end of the run is not mysterious. Put into the formula and you get , a , which is never . So no constant can ever beat a run of values, and for the value at is .

What needs explaining is the other direction: why do six constants reach that when almost every other constant falls short? The answer, as the mathematics has it, is about unique . For positive squarefree , consider the numbers with . If is 3 more than a multiple of 4, also include the numbers where both coefficients are half-integers. These numbers uniquely into exactly for the and . Rabinowitsch showed in 1913 that stays prime for every from 0 to exactly when is a Heegner number. For that number is , the largest one, which is why 41 is the last lucky constant. The page states this and cites it. It does not prove it.

04

Formal statement

What is computed, what is proved, and what is cited

Computed here. For each the laboratory finds the number of consecutive for which is , using exact arithmetic and . For every from 2 to 2,000 the six lucky constants are the only ones whose run reaches , and for exactly those six lies in the list of .

Proved on this page. For every at least 2, gives , so the run has at most terms.

Cited. For positive squarefree , the field has one exactly when is one of 1, 2, 3, 7, 11, 19, 43, 67 and 163 (Heegner 1952, Stark 1967). The run of happens exactly when is among them (Rabinowitsch 1913).

05

Proof

The one argument made in full, and the one only quoted

The short is the one for the ceiling. Expanding, , and has the , which is neither 1 nor itself once . A run of starting at therefore stops no later than .

The reason the six lucky constants reach that ceiling is not proved here. Its needs the arithmetic of the ring (for some this is smaller than the full ring of of , and it is this one that matters): if it has unique , a small that divided would force a relation between and the prime that cannot hold below , and Stark and Heegner showed that unique factorisation occurs for exactly nine positive squarefree values of . The laboratory instead checks the consequence, for every up to 2,000, and shows the list it relies on. A check to 2,000 is a fact about those numbers; the statement for all rests on the .

06

Limits and further questions

The same number, seen from another direction

The number 163 appears a second time in a place that looks unrelated. The value of is , which is with about missing. The same-fact view computes it in exact arithmetic, with no floating point anywhere, and counts the twelve 9s after the point. Doubles cannot show this: they carry about sixteen significant digits, and this number has eighteen digits before the nines even begin.

The explanation is again the . For the larger , and , the value of the modular - at is a whole number, and the -expansion of then makes equal to a whole number minus a tiny correction, whose size shrinks as grows. That is the explanation in Zagier’s chapter on modular forms. The tests check the digits against that expansion.

The view also shows rows that are close and not Heegner: comes within about 22 millionths of a whole number and within about 0.18 millionths. This page has no account of them. And it is a mistake to treat the length of the run as a guide to what comes next: whether any can produce forever is a question this exploration neither asks nor answers, and no non-constant polynomial of one is prime at every whole number.

What is actually established

Every statement on this page, with its status, its exact scope, and the date that status was last checked.

Exhaustively checked

For q = 41, n² + n + 41 is prime for every n from 0 to 39 and equals 41 × 41 at n = 40.

Scope
n from 0 to 40 for q = 41, each value divided by every whole number up to its square root, with exact integer arithmetic. The tests repeat the check with a sieve of Eratosthenes.
Why
For one fixed number the list of possible divisors is finite and the page tries all of it, so each of the forty verdicts is a complete proof about that number. The count of forty is then a finite fact, and nothing about n above 40 follows from it.
Computation (exact)
n = 0 to 40, q = 41, exact BigInt trial division Algorithm euler-primes-1.
Status checked
Proved

For every whole number q at least 2, n² + n + q equals q × q at n = q − 1, so the run of primes has at most q − 1 terms.

Scope
Every q. The proof is one line of algebra, shown on the page.
Why
Substituting n = q − 1 gives (q − 1)² + (q − 1) + q = q² − 2q + 1 + q − 1 + q = q². A square of a number at least 2 is never prime, so the run cannot reach n = q − 1.
Status checked
Exhaustively checked

The constants q for which n² + n + q is prime for every n from 0 to q − 2 are 2, 3, 5, 11, 17 and 41, and they are exactly the q with 4q − 1 equal to 7, 11, 19, 43, 67 or 163, the Heegner numbers above 3.

Scope
Checked here for every q from 2 to 2,000: the run is computed for each, the six lucky ones are the only ones to reach q − 1, and 4q − 1 is a Heegner number for exactly those six. The statement for all q is the cited theorem of Rabinowitsch, which depends on the Stark-Heegner theorem that the nine Heegner numbers are all there are. The page does not prove either.
Why
The check up to 2,000 is a computation, and it agrees with the citation. What lies beyond 2,000 rests on the theorem, whose proof needs algebraic number theory: the numbers a + b√−d (with halves allowed when d is 3 more than a multiple of 4) have unique factorisation exactly when d is a Heegner number, and that is what keeps n² + n + q prime for as long as possible.
Computation (exact)
q = 2 to 2,000, exact BigInt trial division Algorithm euler-primes-1.
Status checked
Exhaustively checked

e^(π√163) is 262,537,412,640,768,743.99999999999925007259…, which is 640,320³ + 744 minus about 7.5 × 10⁻¹³.

Scope
The digits are computed on the page in fixed-point integer arithmetic with sixty guard digits, never with floating point. The tests check them against the q-expansion of the j-invariant, which is a different formula, and against the same digits at two different precisions. The page does not claim a proof of a closed form.
Why
A computation of this kind settles the digits it prints and no more. Why the value is so close to a whole number is explained by the class number one of the field for d = 163, through the j-invariant; that explanation is cited and not proved here.
Computation (exact)
d = 1 to 1,000, up to 200 decimal places, exact integer arithmetic Algorithm euler-primes-1.
Status checked
Proved

The closeness of e^(π√d) to a whole number for the Heegner numbers d = 43, 67 and 163 is explained by the same class-number-one fact that makes 41 a lucky constant.

Scope
Cited, not proved on this page. The page makes no claim about why other d, such as 37 and 58, are also close.
Why
For each of these three values of d, class number one makes the j-invariant at (1 + √−d)/2 an integer. The expansion of j then gives the near-integer.
Status checked

Sources

Review notes show which bibliographic details Mathomaly has checked and which remain unresolved. Checking a publication record does not independently verify its proof.

I’ve checked each citation below against the publication itself, unless it says otherwise. That checks the reference, not the proof.

  1. Leonhard Euler, Extrait d'un lettre de M. Euler le pere à M. Bernoulli concernant le Mémoire imprimé parmi ceux de 1771, p 318, Nouveaux Mémoires de l'académie royale des sciences de Berlin, volume for 1772, pp. 35–36 (Eneström E461), 1774. Link

    The published letter includes Euler's observation about x² − x + 41, equivalent to this page's n² + n + 41 after shifting the input by one.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: library record.

    The University of the Pacific's Euler Archive identifies the published letter, its actual title, E461, publication in 1774 and the 1772 volume.

  2. Georg Rabinowitsch, Eindeutigkeit der Zerlegung in Primzahlfaktoren in quadratischen Zahlkörpern, Journal für die reine und angewandte Mathematik 142, p. 153, 1913. Link

    The criterion for when n² + n + q is prime for every n from 0 to q − 2: exactly when 4q − 1 is a Heegner number. The page states it as cited and does not prove it.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: publisher record.

    Publisher confirms author, article title and 1913 volume 142.

  3. Kurt Heegner, Diophantische Analysis und Modulfunktionen, Mathematische Zeitschrift 56, pp. 227–253, 1952. Link

    The first proof that the list of imaginary quadratic fields of class number one is complete. It was not accepted at first and was vindicated after Stark's proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: publisher record.

    Springer lists Kurt Heegner, the title, volume 56, pages 227–253 and the September 1952 publication date. The paper is behind a paywall.

  4. Harold M. Stark, A complete determination of the complex quadratic fields of class-number one, Michigan Mathematical Journal 14, pp. 1–27, 1967. Link

    Proves that exactly nine imaginary quadratic fields have class number one, those of d = 1, 2, 3, 7, 11, 19, 43, 67 and 163. Together with Heegner, the Stark-Heegner theorem the page cites.

    Bibliographic review:

    AI-assisted source review. Evidence type: author record.

    Section 3 of Stark’s 2007 account gives the class-number result. Its bibliography confirms the title, journal, year, volume and pages of the 1967 paper. The journal’s full text was unavailable during the review.

  5. Don Zagier, Elliptic Modular Forms and Their Applications, The 1-2-3 of Modular Forms, Universitext, pp. 1–103, 2008. Link

    Explains the near-integer for 163 using complex multiplication and the expansion of the modular j-function.

    Bibliographic review:

    AI-assisted source review. Evidence type: source text.

    Proposition 25 and the approximation in section 6.1 connect class number one to the near-integer. Section 6.2 gives the exact value of j for discriminant −163.

  6. A014556 - Euler's "lucky" numbers, The On-Line Encyclopedia of Integer Sequences. Link

    The six lucky constants 2, 3, 5, 11, 17 and 41, which the page also recomputes for every q up to 2,000.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Read the entry: title and the terms 2, 3, 5, 11, 17, 41.

  7. A003173 - Heegner numbers, The On-Line Encyclopedia of Integer Sequences. Link

    The nine Heegner numbers 1, 2, 3, 7, 11, 19, 43, 67 and 163.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Read the entry: title and the terms 1, 2, 3, 7, 11, 19, 43, 67, 163.

(connected by how they work)