than the size of P), the methods of linear algebra can be used (for example, Gaussian elimination) to multiply together these various relations in such a way that the exponents of the primes on the right-hand side are all even: This yields a congruence of squares of the form which can be turned into a factorization of N, This factorization might turn out to be trivial (i.e. ), which can only happen if in which case another try has to be made with a different combination of relations; but a nontrivial pair of factors of N can be reached, and the algorithm will terminate. Pseudocode input: positive integer output: non-trivial factor of Choose bound Let be all primes repeat for to do Choose such that is -smooth Let such that end for Find non-empty such that Let while return Example This example will try to factor N = 84923 using bound B = 7. The factor base is then P = {2, 3, 5, 7}. A search can be made for integers between and N whose squares mod N are B-smooth. Suppose that two of the numbers found are 513 and 537: So Then That is, The resulting factorization is 84923 = gcd(20712 − 16800, 84923) × gcd(20712 + 16800, 84923) = 163 × 521. Optimizations The quadratic sieve is an optimization of Dixon's method. It selects values of x close to the square root of such that x2 modulo N is small, thereby largely increasing the chance of obtaining a smooth number. Other ways to optimize Dixon's method include using a better algorithm to solve the matrix equation, taking advantage of the sparsity of the matrix: a number z cannot have more than factors, so each row of the matrix is almost all zeros. In practice, the block Lanczos algorithm is often used. Also, the size of the factor base must be chosen carefully: if it is too small, it will be difficult to find numbers that factorize completely over it, and if it is too large, more relations will have to be collected. A more sophisticated analysis, using the approximation that a number has all its prime factors less than with probability about (an approximation to the Dickman–de Bruijn function), indicates that choosing too small a factor base is much worse than too large, and that the ideal factor base size is some power of . The optimal