Solution (source code)

= Solution

The <quantum circuit> has one control wire per binary digit and one target <quantum register>. Every control starts in $|0\rangle$, receives a <Hadamard gate>, controls the corresponding power $U^{2^j}$, and then enters the collective inverse <quantum Fourier transform>. Only the control register is measured; the target stays in $|\psi\rangle$.

\Image[/past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2012/iii/paper-67-phase-estimation-circuit.png]
{title=Exact dyadic phase-estimation circuit with controlled powers, inverse Fourier transform, and little-endian output bits}

The omitted intermediate wires continue the pattern $j=0,1,\ldots,m-1$. The inverse <quantum Fourier transform> black box is defined on the integer basis $|k\rangle$ with $k=\sum_j2^jk_j$, so the displayed ordering introduces no hidden bit reversal. The measured bits satisfy
$$
\boxed{x=\sum_{j=0}^{m-1}2^jx_j,\qquad\phi=x/2^m.}
$$
Each controlled power box represents $2^j$ sequential controlled-$U$ uses when only that primitive is available.