Prime number and factorization algorithms. Need some optimizing.