A3: Controlled Gate II

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

Problem Statement

Given an integer nn, implement an n+1n+1-qubit oracle OO on a quantum circuit qc\mathrm{qc}.

For any pair of integers (m,k)(m,k) satisfying 0≤m<20 \leq m < 2 and 0≤k<2n0 \leq k < 2^n, the oracle must perform the following transformation:

  • If k=0k = 0,
∣m⟩∣k⟩n→O∣m⟩∣k⟩n\ket{m} \ket{k}_n \xrightarrow{O} \ket{m} \ket{k}_n
  • If k≠0k \neq 0,
∣m⟩∣k⟩n→O∣m⊕1⟩∣k⟩n\ket{m} \ket{k}_n \xrightarrow{O} \ket{m \oplus 1} \ket{k}_n

Here, ⊕\oplus denotes the XOR operator.

Constraints

from qiskit import QuantumCircuit, QuantumRegister
 
 
def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
 
    return qc

Hints

Open
  • You can consider the way to apply the approach in Problem A2.

Please sign in to submit your answer.