I posted a couple prime-generating fractions on Google+ this weekend and said that I’d post an explanation later. Here it goes.

The decimal expansion of 18966017 / 997002999 is

.019 023 029 037 047 059 073 089 107 127 149 173 199 227 257 …

where each group of three digits is a prime number.

The fraction 4099200041 / 999700029999 produces primes in groups of four digits:

.0041 0043 0047 0053 0061 0071 0083 0097 0113 0131 0151 0173 0197 0223 0251 0281 0313 0347 0383 0421 0461 0503 0547 0593 0641 0691 0743 0797 0853 0911 0971 1033 1097 1163 1231 1301 1373 1447 1523 1601…

What’s going on here? Both fractions come from infinite sums involving prime-generating polynomials. No polynomial in one variable will generate only primes, but several do produce a long sequence of primes.

Euler discovered in 1772 that *n*^{2} – *n* + 41 is prime for values of *n* from -40 to 40. The second fraction above comes from Euler’s polynomial:

The digits in the decimal expansion stop being prime after the 40th quartet because Euler’s polynomial isn’t prime for *n* = 41.

The first fraction above comes from a similar polynomial discovered by Legendre, *n*^{2} + *n* + 17. It produces primes for *n* = -16 to 15.

You can make your own prime-generating fraction by finding a prime-generating polynomial and using the process above. Euler’s polynomial produces 4-digit primes before becoming composite, so the denominator in the sum is 10^{4n}. Legendre’s polynomial produces 3-digit primes for the corresponding denominator in the sum is 10^{3n}.

## Related math posts

For daily tweets on algebra and other math, follow @AlgebraFact on Twitter.

Can an isotropic physical system generate anisotropic response?

how have you calculated the sums? into fractions

The base twelve version of the 4-digit-grouping one looks quite similar to the decimal version. The denominator of 34bb540035/bbb90002bbbb fits the pattern “r-1 r-1 r-1 r-3 0002 r-1 r-1 r-1 r-1”. How does that come about?

This is a project euler problem, btw.

I haven’t seen the project euler problem. Could you send a link?

In your first example, you left off the digits right where the sequence starts to be non-prime?

> FatRat.new(18966017, 997002999).base(10, 51).comb(/\d\d\d/).map({ $_ => $_.Int.is-prime }).join(“\n”)

019 True

023 True

…

257 True

289 False

323 False