Quadratic Sieve implementation