xyrasinclair.com / archive / evanward.org

Primality Testing, Factorization, and Sieving Implementation

March 3, 2019 — Code

I figured that for my daily post today, I would learn Javascript and figure out how to make this website more interactive. I decided to write primality testing and prime factorization scripts and include them below:

Update: I've included a prime sieving script. Additionally, these only work for integers from 2 to 2^53.

Test if a number is prime:

Factor a number into its prime components:

Calculate all prime numbers under n:

These algorithms are only moderately faster over the most naive implementations. There are much faster algorithms out there!

Published on evanward.org. Recovered from the Internet Archive capture and served here verbatim.