= Solution
For $r$ brackets the control-zero branch still does nothing, and the control-one branch applies $G^r$ to the target. Immediately before the final two <Hadamard gates>, the <quantum state> is
$$
\frac{|0\rangle|+\rangle+|1\rangle G^r|+\rangle}{\sqrt2}.
$$
For the <constant function> with $k=0$, the <phase oracle> is $U_f=-I$, so $G=(-X)(-I)=X$. Since $|+\rangle$ is an <eigenstate> of the <Pauli X gate> with <eigenvalue> $+1$, $G^r|+\rangle=|+\rangle$ for every integer $r$. The final two <Hadamard gates> therefore give
$$
\boxed{|\Psi_{k=0}(r)\rangle=|00\rangle,\qquad \langle Z\otimes I\rangle=+1.}
$$
In particular, the first <qubit> always ends in $|0\rangle$.
For the <constant function> with $k=2$, $U_f=I$ and $G=-X$, so $G^r|+\rangle=(-1)^r|+\rangle$. Thus the target remains in $|+\rangle$, and the top <qubit> before its final <Hadamard gate> is $(|0\rangle+(-1)^r|1\rangle)/\sqrt2$. The sign is a <relative quantum phase> between the control branches. The <Hadamard gate> converts it into the <integer parity> of $r$:
$$
\boxed{|\Psi_{k=2}(r)\rangle=|r\bmod2\rangle\otimes|0\rangle,\qquad
\langle Z\otimes I\rangle=(-1)^r.}
$$
The first <qubit> is therefore $|0\rangle$ for even $r$ and $|1\rangle$ for odd $r$, including all requested $r>1$.
Back to article page