This result was conjectured by Gauss and proved up to minor flaws by Kurt Heegner in 1952. Alan Baker and Harold Stark independently proved the result in 1966, and Stark further indicated the gap in Heegner's proof was minor.[2]

Euler's prime-generating polynomial

Euler's formula, with n{\displaystyle n} taking the values 1,... 40 is equivalent to

n2+n+41,{\displaystyle n^{2}+n+41,\,}

with n{\displaystyle n} taking the values 0,... 39, and Rabinowitz[3] proved that

n2+n+p{\displaystyle n^{2}+n+p\,}

gives primes for n=0,…,p−2{\displaystyle n=0,\dots ,p-2} if and only if its discriminant 1−4p{\displaystyle 1-4p} equals minus a Heegner number.

(Note that p−1{\displaystyle p-1} yields p2{\displaystyle p^{2}}, so p−2{\displaystyle p-2} is maximal.)
1, 2, and 3 are not of the required form, so the Heegner numbers that work are 7,11,19,43,67,163{\displaystyle 7,11,19,43,67,163}, yielding prime generating functions of Euler's form for 2,3,5,11,17,41{\displaystyle 2,3,5,11,17,41}; these latter numbers are called lucky numbers of Euler by F. Le Lionnais.[4]

If τ{\displaystyle \tau } is a quadratic irrational, then the j-invariant is an algebraic integer of degree |Cl(Q(τ))|{\displaystyle |{\mbox{Cl}}(\mathbf {Q} (\tau ))|}, the class number of Q(τ){\displaystyle \mathbf {Q} (\tau )} and the minimal (monic integral) polynomial it satisfies is called the Hilbert class polynomial. Thus if the imaginary quadratic extension Q(τ){\displaystyle \mathbf {Q} (\tau )} has class number 1 (so d is a Heegner number), the j-invariant is an integer.

where the reason for the squares is due to certain Eisenstein series. For Heegner numbers d<19{\displaystyle d<19}, one does not obtain an almost integer; even d=19{\displaystyle d=19} is not noteworthy.[11] The integer j-invariants are highly factorisable, which follows from the 123(n2−1)3=(22⋅3⋅(n−1)⋅(n+1))3{\displaystyle 12^{3}(n^{2}-1)^{3}=(2^{2}\cdot 3\cdot (n-1)\cdot (n+1))^{3}} form, and factor as,

The roots of the cubics can be exactly given by quotients of the Dedekind eta functionη(τ), a modular function involving a 24th root, and which explains the 24 in the approximation. In addition, they can also be closely approximated by algebraic numbers of degree 4,[13]

with the j-invariants appearing again. These sextics are not only algebraic, they are also solvable in radicals as they factor into two cubics over the extension Q5{\displaystyle \mathbb {Q} {\sqrt {5}}} (with the first factoring further into two quadratics). These algebraic approximations can be exactly expressed in terms of Dedekind eta quotients. As an example, let τ=(1+−163)/2{\displaystyle \tau =(1+{\sqrt {-163}})/2}, then,

Consecutive primes

Given an odd prime p, if one computes k2(modp){\displaystyle k^{2}{\pmod {p}}} for k=0,1,…,(p−1)/2{\displaystyle k=0,1,\dots ,(p-1)/2} (this is sufficient because (p−k)2≡k2(modp){\displaystyle (p-k)^{2}\equiv k^{2}{\pmod {p}}}), one gets consecutive composites, followed by consecutive primes, if and only if p is a Heegner number.[14]

^These can be checked by computing eπd−7443{\displaystyle {\sqrt[{3}]{e^{\pi {\sqrt {d}}}-744}}} on a calculator, and
196884/eπd{\displaystyle 196\,884/e^{\pi {\sqrt {d}}}} for the linear term of the error.

^The absolute deviation of a random real number (picked uniformly from [0,1], say) is a uniformly distributed variable on [0, 0.5], so it has absolute average deviation and median absolute deviation of 0.25, and a deviation of 0.22 is not exceptional.