M is closed under multiplication. This follows from thinking of it is an exercise modulo n. From this point on our reasoning and code are all modulo n. The square of each number yi in our collection is a product of our small primes with non negative exponents:
yi2 = p1ei1 p2ei2 ...
We have as many yi’s as small primes. We can find a subset of the yi2’s which, when multiplied together, have exponents that are all even. Call this product S. We can find x such that x2 = S.
Recall that the yi’s were themselves quadratic residues and that we can find solve xi = yi(mod n) for the subset of yi’s.