31 lines
930 B
Text
31 lines
930 B
Text
local int = require "int"
|
|
local fmt = require "fmt"
|
|
|
|
local limit <const> = 1e9
|
|
local gap_starts = {}
|
|
local primes = int.primes(limit * 5, true, 128 * 1024)
|
|
for i = 2, #primes do
|
|
local gap = primes[i] - primes[i - 1]
|
|
if !gap_starts[gap] then gap_starts[gap] = primes[i - 1] end
|
|
end
|
|
local pm = 10
|
|
local gap1 = 2
|
|
while true do
|
|
while !gap_starts[gap1] do gap1 += 2 end
|
|
local start1 = gap_starts[gap1]
|
|
local gap2 = gap1 + 2
|
|
if !gap_starts[gap2] then
|
|
gap1 = gap2 + 2
|
|
continue
|
|
end
|
|
local start2 = gap_starts[gap2]
|
|
local diff = math.abs(start2 - start1)
|
|
if diff > pm then
|
|
fmt.print("Earliest difference > %,s between adjacent prime gap starting primes:", pm)
|
|
fmt.print("Gap %d starts at %,s, gap %d starts at %,s, difference is %,s.\n", gap1, start1, gap2, start2, diff)
|
|
if pm == limit then break end
|
|
pm *= 10
|
|
else
|
|
gap1 = gap2
|
|
end
|
|
end
|