Online computation of the first primes and twin primes

 

Using the famous Sieve of Eratosthenes (discovered by the Greek Eratosthenes 276 BC-194 BC),  it is possible to perform an online computation of the first prime numbers with a small JavaScript program (you can view the source of this program using a command like View/Source in your browser). Therefore your browser must support JavaScript if you want to test this small application! At the end of the array of primes, the number p(x) of primes less than x founded is given. The primes may be computed up to x = 50000 (it may take a few seconds to perform) but this bound can be increased inside the program.  

A nice interactive illustration of how the Eratosthenes' sieve works may be found here (also in JavaScript). 

Compute primes

To compute the first primes click on the Compute primes button


     

Primes up to x =   1000    5000    10000     100000   

If you change the default number of primes click again on the Compute primes button to update the array of primes. If the number of searched primes is important it may take a few seconds to get the result of the computation. 

Compute twin primes

The same method allows to compute the twin primes, that is consecutive primes distant of 2. For example, 11 and 13 are twin primes. The number p2(x) of twin primes less than x and the computation of Brun's constant (that is the sum of the inverse of the twin primes) are also given at the end of the file. To find p2(x) for large values of x (say up to 1015 or more), note that most algorithms are variants of Eratosthenes' sieve. 

To compute the first twin primes click on the Compute twin primes button


     

Twin Primes up to x =   1000    5000    10000     100000   

If you change the default number of twin primes click on the Compute twin primes button to update the array of twin primes.