Editorial
Editorial on Hint
Hint: You can consider the following oracle without c first.
∣k⟩nOexp(2n2πiak)∣k⟩n
First, expand k in binary representation:
k=k0+2k1+⋯+2n−1kn−1(k0,k1,…,kn−1∈{0,1})
Then, the phase change of each computational basis state can be decomposed into each qubit.
exp(2n2πiak)∣k⟩n=exp(2n2πia(k0+2k1+⋯+2n−1kn−1))∣k0⟩∣k1⟩⋯∣kn−1⟩=exp(2n2πiak0)∣k0⟩exp(2n2πia2k1)∣k1⟩⋯exp(2n2πia2n−1kn−1)∣kn−1⟩
Therefore, this oracle can be implemented by applying a phase gate P(θ) with θ=2πa2i/2n to each qubit.
Editorial on the Problem
As in the hint, the phase change of each computational basis state can be decomposed into each qubit.
exp(2n2πiakc)∣k⟩n∣c⟩1=exp(2n2πia(k0+2k1+⋯+2n−1kn−1)c)∣k0⟩∣k1⟩⋯∣kn−1⟩∣c⟩=exp(2n2πiak0c)∣k0⟩⋯exp(2n2πia2n−1kn−1c)∣kn−1⟩∣c⟩
Since the quantum bit ∣c⟩ can be interpreted as a control bit, you can apply controlled phase gates CP(θ) with θ=2πa2i/2n with ∣c⟩ as the control bit.
Sample Code
Below is a sample program:
import math
from qiskit import QuantumCircuit
def solve(n: int, a: int) -> QuantumCircuit:
qc = QuantumCircuit(n + 1)
for i in range(n):
theta = 2 * math.pi * a * 2**i / 2**n
qc.cp(theta, n, i)
return qc