Finished fermat and MillerRabin primality tests, as well as helper functions