Editorial
The state after the application of the oracle can be represented by placing parentheses and nesting the operation for two qubits as follows:
That is, using each qubit from to as control bits and as the target bit, the oracle can be realized by applying a total of gates.
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit, QuantumRegister
def solve(n: int) -> QuantumCircuit:
x, y = QuantumRegister(n), QuantumRegister(1)
qc = QuantumCircuit(x, y)
for i in range(n):
qc.cx(x[i], y)
return qc