Implement basic quadratic sieve.