Cleaned up is_prime_lenstra and factor R using p+1 algorithm.