Safety First

Be careful — this code might be very evil! Only compile and run this program if you trust me and the code herein.

Signed checksums and gpg signatures are included in every package for security. Here is an example of using the GNU Privacy Guard to verify the integrity of a program.

Copying and pasting the code samples below can be dangerous. I recommend not copying and pasting as the root or administrative user.

prime

This program outputs the first million primes!

Give it a Spin



Estimated times for above demo (running on a single board computer):

n:             nth Prime:
5              11         found in    0.000135 seconds
10             29         found in    0.000203 seconds
100            541        found in    0.001669 seconds
1000           7919       found in    0.04205  seconds
10000          104729     found in    1.26253  seconds
100000         1299709    found in   34.9215   seconds
1000000        15485863   found in 1041.71     seconds (~18 minutes)



This program uses the Sieve of Eratosthenes to compute the first million primes. On my laptop it takes about 30 seconds, but it may be faster or slower on yours. See it in action!


Estimated times for modern-ish laptop:

n:             nth Prime:
5              11
10             29
100            541
1000           7919
10000          104729
100000         1299709
1000000        15485863

found in 31.0171 seconds




Quick Start


Clone, compile, run

# clone
git clone https://github.com/lbeckman314/prime
cd prime

# compile
g++ src/prime.cpp -o prime

# run
./prime




Alternative Installation


1. Download

wget http://www.liambeckman.com/pkgs/prime/prime.tar.gz
# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/prime/prime.tar.gz -o prime.tar.gz


Optional (but recommended): verify file integrity

#-------------------------------#
# RECIEVE GPG KEYS
#-------------------------------#

gpg --keyserver pgp.mit.edu --recv-keys AC1CC079

#-------------------------------#
# RECIEVE SHA256SUMS
#-------------------------------#

wget http://www.liambeckman.com/pkgs/prime/sha256sums.txt{,.asc}
# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/prime/sha256sums.txt{,.asc} -o sha256sums.txt -o sha256sums.txt.asc

#-------------------------------#
# VERIFY SHA256SUMS
#-------------------------------#

gpg --verify sha256sums.txt.asc

# gpg: Signature made Tue Oct 31 11:11:11 2017 PDT using RSA key ID AC1CC079
# gpg: Good signature from "liam beckman ("I only want to live in peace, plant potatoes, and dream!" -Tove Jansson) <lbeckman314@gmail.com>" [unknown]

#-------------------------------#
# VERIFY FILE INTEGRITY
#-------------------------------#

sha256sum -c sha256sums.txt 2>/dev/null | grep prime.tar.gz

# prime.tar.gz: OK

#-------------------------------#
# OPTIONALLY REMOVE PUBLIC KEY
#-------------------------------#

# to remove my public key from your public key ring, simply
gpg --delete-key AC1CC079


2. Extract

tar -zxvf prime.tar.gz
# or if you downloaded the zip file
# unzip prime.zip


3. Compile and run

g++ src/prime.cpp -o prime
./prime



Uninstallation


1. Delete the directory/folder.

rm -rfI prime