Some Faster Algorithms for Finding Large Prime Gaps

Abstract

This paper investigates the problem of finding large prime gaps (the difference between two consecutive prime numbers, pi+1 – pi) and on the development of a small, efficient program for generating such large prime gaps for a single computer, a laptop or a workstation. In Wikipedia [1], one can find a table of all known record prime gaps less than 264, the record is a 20 decimal digit number. We wanted to go beyond 64 bit numbers and demonstrate algorithms that do not needed a huge number of computers in a grid to produce useful results. After some preliminary tests, we found that the Sieve of Eratosthenes, SE, from the year 250 BC was the fastest for finding prime numbers and it could also be made space efficient. Each odd number is represented by one bit and when storing 8 odd numbers in a single byte (representing 16 consecutive numbers ignoring the even numbers), we found that we should not make one long SE table, but instead divide the SE table into segments (called SE segments), each of length 108 or 109 and dynamically generate the necessary SE segments as to find prime numbers. First, we made a basic segment of all prime numbers < 108 (in less than a second). We also relied heavily on the old observation [2] that when using SE to find all prime numbers ?????, we cross out all numbers using the prime numbers ???? ? ?????, and that the first number crossed off when crossing out for prime number p is p2. When we want to find prime gaps, we first create one or more consecutive SE in that range, say starting on 274 and ending with the value M – initially these big segments are crossed out by our first basic set of primes < 108 , To find all prime number in these big segments, we next need the rest of prime numbers ???? ? ????? . These can be all be constructed by using our first set of prime numbers to generate segments of consecutive SE from 108. The primes in these segments are used to cross out in the big SE segment and can then be discarded (each prime used only once). Our most significant algorithm was to find a simple formula for using primes from a range 3 – 236 to cross out the non-primes in any SE segment without crossing out in all the numbers between 236 and 272. This leads to an exponential saving in both space and execution time. In addition to this, we created a small package Int3 to represent numbers > 264 by storing 8 decimal values in each of 3 integer variables together with the necessary mathematical operations. The Int3 package can handle numbers up to 24 decimal digits and is significantly faster than the BigInteger package in the Java library. We also created a faster algorithm for finding all record prime gaps. The results presented in this paper are some tables of prime gaps for primes significantly larger than 264 and data supporting an observation that big prime gaps in these segments are much more frequent than the ones we find in the Wikipedia table where the search starts at prime number 3. Our combined set of algorithms is also sufficiently fast to test every entry in the Wikipedia table in less than 5 minutes. We conclude by reflecting on the use of brute force (more computers) versus smarter algorithms

    Similar works