Here are two apparently unrelated things you may have seen before. The **first** is an observation going back to Euler that the polynomial

produces a long sequence of primes. Namely, the values are prime for *n* = 1, 2, 3, …, 40.

The **second** is that the number

is extraordinarily close to an integer. This number is known as Ramanujan’s constant. It differs from its nearest integer by 3 parts in 10^{30}. Ramanujan’s constant equals

262537412640768743.99999999999925…

**There is a connection** between these two facts: The polynomial

returns primes for *n* = 1, 2, 3, …, *k* − 1 primes if 4*k* − 1 is a **Heegner number**, and

is almost an integer if *d* is a (large) Heegner number.

Source: The Book of Numbers by Conway and Guy.

## Heegner numbers

So what’s a Heegner number and how many are there? An integer *d* is a Heegner number if the ring generated by appending √−*d* to the integers has unique factorization. There are nine such numbers:

1, 2, 3, 7, 11, 19, 43, 67, 163.

There’s deeper stuff going on here than I understand—modular forms, the *j*-function, etc.—so this post won’t explain everything. There’s something unsatisfying about saying something is “almost” an integer without quantifying. There’s a way to be more precise, but we won’t go there. Instead, we’ll just play with the results.

## Mathematica computation

First we look at the claim that *n*² − *n* + *k* produces primes for *n* = 1 through *k* − 1 if 4*k* − 1 is a Heegner number. The values of *k* such that 4*k* − 1 is a Heegner number are 2, 3, 5, 11, and 17. The following code shows that the claim is true for these values of *k*.

k = {2, 3, 5, 11, 17} claim[x_] := AllTrue[ Table[n^2 - n + x, {n, x - 1}], PrimeQ ] AllTrue[k, claim]

This returns `True`

, so the claim is true.

As for exp(π √*d*) being close to an integer, this apparently only true for the last three Heegner numbers.

h = {1, 2, 3, 7, 11, 19, 43, 67, 163} For[i = 1, i < 10, i++, Print[ AccountingForm[ N[ Exp[ Pi Sqrt[ h[[i]] ] ], 31 ] ] ] ]

(The function `AccountingForm`

suppresses scientific notation, making it easier to see where the decimal portion of the number starts.)

Here are the results:

23.1406926327792 85.0196952232072 230.7645883191458 4071.9320952252610 33506.1430655924387 885479.7776801543194 884736743.9997774660349 147197952743.9999986624548 262537412640768743.9999999999993

I manually edited the output to align the decimal points and truncate the decimal places beyond that needed to show that the last number is not an integer.

“The Heegner numbers of the form 4k + 1 are 2, 3, 5, 11, and 17.” Did not understand this.

That should have said “The values of k such that 4k-1 is a Heegner number are 2, 3, 5, 11, and 17.”

Thanks. I just fixed it.