Write . Applying the phase gate
to qubit contributes . The product of these gates is therefore
Similarly, for and , apply a controlled phase gate
between every pair . The accumulated phase is
The controlled phase gates implement