Skip to content

ppetr/zillion-primes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zillion primes

Disclaimer: This is not an officially supported Google product.

This program uses the Sieve of Eratosthenes to generate primes up to a given bound.

On a standard low-end Intel Core i5 it produces ~7.9M primes per second.

It uses approximately 0.024√n bytes of RAM to compute primes up to n.

Output

The program emits primes to stdout encoded as 64-bit binary little-endian numbers.

This format is easily readable by programs, and can be even mmap-ed as an int64_t[] array. Also allows to quickly read an N-th prime.

Compilation

$ clang++ -O3 sieve.cc -o sieve

g++ works just as well, it just produces slightly slower (~15%) binary.

Testing

The first 50.000.000 primes should satisfy the following hash:

$ ./sieve 982451653 | sha256sum
17d28fa909939b450dbd6b8923a1001c61bdc8cedb5e44a07f9f90b4d36ab279  -

About

Fast implementation of the Sieve of Erathosthenes

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages