The first prime gap of 2 is between 3 and 5. This is followed by another gap of 2 between 5 and 7. What number n>2 has the property that the first prime gap of n is followed by another gap of n?
My interpretation of the problem is not just to find 3 consecutive primes such that the two gaps are the same, but also that these will be the first and second instances of that particular prime gap size.
So, for example 23 to 29 is the first instance of a gap of 6. But it is followed by 31 and a gap of 2. So the first prime gap of 6 is not followed by another gap of 6.
My solution:
3 primes 2 gaps
3 5 7 2 2
199 211 223 12 12
n = 12
----------
import sympy as s
gaps = {}
prior = 2
for n in range(10000):
new = s.nextprime(prior)
gap = new - prior
if gap not in gaps:
future = s.nextprime(new)
futuregap = future - new
gaps[gap] = [new, futuregap]
if gap == futuregap:
print(prior, new, future, ' ', gap, futuregap)
prior = new
|
Posted by Larry
on 2024-12-24 11:38:24 |