Where can I search pairs of primes, of certain gap?

98 Views Asked by At

Is there an online database that lets me search prime pairs by the gap among primes?

I know of the primes.utm.edu's search, and I see twin primes (gap = $2$) can be searched by typing "twin", but how can I search any other valid gap, for example; gap of $12$?

I couldn't find on their site a guide to valid comment commands for searching specific types of primes. "Advanced Search" mentions some commands, but I couldn't figure out of how to set a gap other than obvious "twin" for gap $2$. I tried "sexy" for gap of $6$ and "cousin" for gap of 4, but that does not work; I need to be able to search any valid gap.

2

There are 2 best solutions below

0
On BEST ANSWER

This will do the job, is a little Python program I have prepared:

In this link you can run it and modify the desired gap you want (just in case: you do not need to login, just close the optional little login window that appears and click the run button, you can modify content in the left side for a different prime gap family): https://repl.it/IMBz/1

It is not optimized and the online version is slow, but will help you initially for a first research. By the way, if you install Python in your computer, you can run it even faster, here is the code, enjoy!

from sympy import nextprime

n=2
#list of primes
lop=[]
#will contain gap calculation
lastgap=0
#will contain previous prime to current prime
prevpr=0

#set here the desired prime gap family to be found
desired_gap=6

#set here the limit of your test n<test_limit
test_limit=1000
counter=0

while counter<test_limit:
  prevpr=n
  n=nextprime(n+1)
  lastgap=n-prevpr
  if lastgap==desired_gap:
    lop.append(prevpr)
  counter=counter+1

# will print the desired prime gap family
print("Primes whose distance to the next prime is "+str(desired_gap)+" lower than "+str(test_limit))
print(lop)
1
On

The easiest way to do this is probably to:

1) Download a list of primes (e.g. from https://primes.utm.edu/)

2) Take the 1-d difference d(n), i.e. if the n-th prime is p(n), calculate d(n)=p(n)-p(n-1) , with the convention that $p(0) = 0$.

3) Find the indices where d(n) is the desired gap (which you can do by one pass over the d(n) list). Then, print out p(n-1) and p(n) for d(n) being the desired gap.

The website probably caches a list of d(n)'s or the p(n) and p(n-1)'s of this type and displays it when queried.

You could do something like make a hashtable with keys d(n) and for each d(n), store a list with the n's for that d(n). Then, you could go to the k-th d gap prime by accessing the hash table with key d(n) and looking at the k th element of that list (call it m), and printing out p(m) and p(m - 1).


The FAQ suggests running a sieve algorithm (e.g. this) may be faster than reading the list from disk. But the same idea would work.