improved runtime.

optimized check prime function. to check if any previously found primes
are factors and up to sqrt(n)