Problem Statement
Let n be a positive integer. Consider a list [p0,p1,...,p2n−1] of length 2n.
We define the following 2 operations:
- Operation 1: Move the first element to the end
[p0,p1,...,p2n−1]→[p1,...,p2n−1,p0]
- Operation 2: Reverse the entire list
[p0,p1,...,p2n−1]→[p2n−1,...,p1,p0]
Let g(m,k) be the concatenation of the following actions:
- First, apply Operation 1 for k times.
- Then, apply Operation 2 for m times.
Given integers n, mbefore, kbefore, mafter and kafter, implement an n+1-qubit oracle O on a quantum circuit qc.
For any pair of integers (m,k) satisfying 0≤m<2 and 0≤k<2n, the oracle must satisfy
∣m⟩∣k⟩nO∣m′⟩∣k′⟩n
Here, 0≤m′<2 and 0≤k′<2n must satisfy the following condition:
- The operation g(m′,k′) is equivalent to applying g(mbefore,kbefore)→g(m,k)→g(mafter,kafter) in order.
Constraints
- 2≤n≤10
- 0≤mbefore<2
- 0≤kbefore<2n
- 0≤mafter<2
- 0≤kafter<2n
- The quantum circuit depth must not exceed 300.
- 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
def solve(n: int, m_before: int, k_before: int, m_after: int, k_after: int) -> QuantumCircuit:
qc = QuantumCircuit(n + 1)
# Write your code here:
return qc