A3: Controlled Gate II

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

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

The oracle OO acts on basis states mkn\ket{m}\ket{k}_n, where 0m<20 \leq m < 2 and 0k<2n0 \leq k < 2^n, as follows:

  • If k=0k = 0,
mknOmkn.\ket{m} \ket{k}_n \xrightarrow{O} \ket{m} \ket{k}_n.
  • Otherwise,
mknOm1kn.\ket{m} \ket{k}_n \xrightarrow{O} \ket{m \oplus 1} \ket{k}_n.

Here, \oplus denotes the XOR operator.

Constraints

  • 1n101 \leq n \leq 10
  • The circuit depth must not exceed 44.
  • Integers must be encoded by little-endian.
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
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.