B2: XOR Oracle

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

Problem Statement

You are given an integer nn. Implement the oracle OO on a quantum circuit qc\mathrm{qc} consisting of an nn-qubit register x\mathbf{x} and a 11-qubit register yy, and acting on the computational basis states as

∣x⟩∣y⟩→O∣x⟩∣y⊕x1⊕x2⊕...⊕xn⟩\ket{\mathbf{x}}\ket{y} \xrightarrow{O} \ket{\mathbf{x}}\ket{y \oplus x_1 \oplus x_2 \oplus ... \oplus x_n}

Here, xix_i denotes the ii-th qubit of x\mathbf{x}.

Constraints

  • 1≤n≤101 \leq n \leq 10
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit, QuantumRegister
 
 
def solve(n: int) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:
 
    return qc

Sample Input

  • ∣x⟩∣y⟩=12(∣101⟩+∣010⟩)\ket{\mathbf{x}}\ket{y} = \frac{1}{\sqrt{2}} (\ket{101} + \ket{010}): The implemented oracle OO should perform the following transformation.
∣x⟩∣y⟩=12(∣101⟩+∣010⟩)→O12(∣100⟩+∣011⟩)\ket{\mathbf{x}}\ket{y} = \frac{1}{\sqrt{2}} (\ket{101} + \ket{010}) \xrightarrow{O} \frac{1}{\sqrt{2}} (\ket{100} + \ket{011})

Hints

Open
  • You can get the number of qubits nn in x\mathbf{x} as follows:
n = len(x)
  • You can apply the quantum gate gg to the ii-th qubit of x\mathbf{x} as follows:
qc.g(x[i - 1])

Please sign in to submit your answer.