Solution (source code)

= Solution

A final oracle call evaluates $f$ on the definite input $a$:
$$
\boxed{
|\Phi_3\rangle=(-1)^b|a\rangle
|1\oplus f(a)\rangle
=(-1)^b|a\rangle
|1\oplus a\cdot a\oplus b\rangle}.
$$
Since $a\cdot a$ modulo two is the parity of the Hamming weight of $a$, this form also determines the last-qubit measurement.