B2: XOR Oracle

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given an integer nn. Implement the oracle OO on a quantum circuit qc\mathrm{qc} consisting of n+1n+1 qubits, and acting on the computational basis states as

ψ=xyOxyx1x2...xn.\ket{\psi} = \ket{\mathbf{x}}\ket{y} \xrightarrow{O} \ket{\mathbf{x}}\ket{y \oplus x_1 \oplus x_2 \oplus ... \oplus x_n}.

x=x1,...,xn\ket{\mathbf{x}}=\ket{x_1,...,x_n} denotes the first nn qubits of the circuit and y\ket{y} denotes the last one.

Constraints

  • 1n101 \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

  • ψ=12(101+010)\ket{\psi} = \frac{1}{\sqrt{2}} (\ket{101} + \ket{010}): The implemented oracle OO should perform the following transformation.
ψ=12(101+010)O12(100+011)\ket{\psi} = \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 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])

Please sign in to submit your answer.