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
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 prime 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.
- n = 00² + 0 + 41 = 41prime
- n = 11² + 1 + 41 = 43prime
- n = 22² + 2 + 41 = 47prime
- n = 33² + 3 + 41 = 53prime
- n = 44² + 4 + 41 = 61prime
- n = 55² + 5 + 41 = 71prime
- n = 66² + 6 + 41 = 83prime
- n = 77² + 7 + 41 = 97prime
- n = 88² + 8 + 41 = 113prime
- n = 99² + 9 + 41 = 131prime
- n = 1010² + 10 + 41 = 151prime
- n = 1111² + 11 + 41 = 173prime
- n = 1212² + 12 + 41 = 197prime
- n = 1313² + 13 + 41 = 223prime
- n = 1414² + 14 + 41 = 251prime
- n = 1515² + 15 + 41 = 281prime
- n = 1616² + 16 + 41 = 313prime
- n = 1717² + 17 + 41 = 347prime
- n = 1818² + 18 + 41 = 383prime
- n = 1919² + 19 + 41 = 421prime
- n = 2020² + 20 + 41 = 461prime
- n = 2121² + 21 + 41 = 503prime
- n = 2222² + 22 + 41 = 547prime
- n = 2323² + 23 + 41 = 593prime
- n = 2424² + 24 + 41 = 641prime
- n = 2525² + 25 + 41 = 691prime
- n = 2626² + 26 + 41 = 743prime
- n = 2727² + 27 + 41 = 797prime
- n = 2828² + 28 + 41 = 853prime
- n = 2929² + 29 + 41 = 911prime
- n = 3030² + 30 + 41 = 971prime
- n = 3131² + 31 + 41 = 1,033prime
- n = 3232² + 32 + 41 = 1,097prime
- n = 3333² + 33 + 41 = 1,163prime
- n = 3434² + 34 + 41 = 1,231prime
- n = 3535² + 35 + 41 = 1,301prime
- n = 3636² + 36 + 41 = 1,373prime
- n = 3737² + 37 + 41 = 1,447prime
- n = 3838² + 38 + 41 = 1,523prime
- n = 3939² + 39 + 41 = 1,601prime
- 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
| n | Value | Prime |
|---|---|---|
| 0 | 41 | yes |
| 1 | 43 | yes |
| 2 | 47 | yes |
| 3 | 53 | yes |
| 4 | 61 | yes |
| 5 | 71 | yes |
| 6 | 83 | yes |
| 7 | 97 | yes |
| 8 | 113 | yes |
| 9 | 131 | yes |
| 10 | 151 | yes |
| 11 | 173 | yes |
| 12 | 197 | yes |
| 13 | 223 | yes |
| 14 | 251 | yes |
| 15 | 281 | yes |
| 16 | 313 | yes |
| 17 | 347 | yes |
| 18 | 383 | yes |
| 19 | 421 | yes |
| 20 | 461 | yes |
| 21 | 503 | yes |
| 22 | 547 | yes |
| 23 | 593 | yes |
| 24 | 641 | yes |
| 25 | 691 | yes |
| 26 | 743 | yes |
| 27 | 797 | yes |
| 28 | 853 | yes |
| 29 | 911 | yes |
| 30 | 971 | yes |
| 31 | 1,033 | yes |
| 32 | 1,097 | yes |
| 33 | 1,163 | yes |
| 34 | 1,231 | yes |
| 35 | 1,301 | yes |
| 36 | 1,373 | yes |
| 37 | 1,447 | yes |
| 38 | 1,523 | yes |
| 39 | 1,601 | yes |
| 40 | 1,681 | no, 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
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.
- n = 00² + 0 + 41 = 4141 is primeNothing from 2 to 6 divides 41, and 7 × 7 is already more than 41.
- n = 11² + 1 + 41 = 4343 is primeNothing from 2 to 6 divides 43, so the second value survives too.
- n = 3939² + 39 + 41 = 1,6011,601 is primeThe fortieth value. No whole number from 2 to 40 divides it.
- n = 4040² + 40 + 41 = 1,68141 × 411,681 = 41², so the run of primes ends. This was always going to happen at n = 40: for any q, n = q − 1 gives exactly q × q.
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 prime, 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 square root, because a divisor larger than the square root would have to be paired with a smaller one. If none divides, the value is prime 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.
Why it starts to make sense
Forty in a row is a lot, and it is not a theorem
For the first forty values, to , are all prime. Euler 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 prime, 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.
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 perfect square, which is never prime. 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 limit when almost every other constant falls short? The answer, as the mathematics has it, is about unique factorisation. For positive squarefree , consider the numbers with integer coefficients. If is 3 more than a multiple of 4, also include the numbers where both coefficients are half-integers. These numbers factor uniquely into primes exactly for the Heegner numbers 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.
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 prime, using exact integer arithmetic and trial division. 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 Heegner numbers.
Proved on this page. For every at least 2, gives , so the run has at most terms.
Cited. For positive squarefree , the field has class number one exactly when is one of 1, 2, 3, 7, 11, 19, 43, 67 and 163 (Heegner 1952, Stark 1967). The run of primes happens exactly when is among them (Rabinowitsch 1913).
Proof
The one argument made in full, and the one only quoted
The short proof is the one for the ceiling. Expanding, , and has the divisor , which is neither 1 nor itself once . A run of primes starting at therefore stops no later than .
The reason the six lucky constants reach that ceiling is not proved here. Its proof needs the arithmetic of the ring (for some this is smaller than the full ring of integers of , and it is this one that matters): if it has unique factorisation, a small prime 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 theorem.
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 integer 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 class number. For the larger Heegner numbers, and , the value of the modular -function 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 polynomial can produce primes forever is a question this exploration neither asks nor answers, and no non-constant polynomial of one variable 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.
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
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
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
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
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Related explorations
(connected by how they work)