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!