B6: Quantum Arithmetic II

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

Problem Statement

You are given integers n, m, S0, S1, ⋯ , Sn−1n,\ m,\ S_0,\ S_1,\ \cdots,\ S_{n-1}.

For an integer x=x0+21x1+⋯2n−1xn−1x = x_0 + 2^1 x_1 + \cdots 2^{n-1}x_{n-1} (xi∈{0,1})\left(x_i \in \{0, 1\}\right) in the range from 00 (inclusive) to 2n2^n (exclusive), define the function f(x)f(x) by

f(x)=S0x0+S1x1+⋯+Sn−1xn−1\begin{equation} f(x) = S_0 x_0 + S_1 x_1 + \cdots + S_{n-1}x_{n-1} \nonumber \end{equation}

Implement the n+mn+m-qubit oracle OO acting on computational basis states as

∣x⟩n∣0⟩m→O∣x⟩n∣f(x) mod 2m⟩m\begin{equation} \ket{x}_{n}\ket{0}_{m} \xrightarrow{O} \ket{x}_{n}\ket{f(x)\ \mathrm{mod}\ 2^m}_{m} \nonumber \end{equation}

for any integer xx such that 0≤x<2n0 \leq x < 2^n.

Constraints

  • 1≤n,m≤91 \leq n, m \leq 9
  • n+m≤10n + m \leq 10
  • 0≤Sk<2m0 \leq S_k < 2^m
  • The quantum circuit depth must not exceed 5050.
  • 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, m: int, S: list[int]) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(m)
    qc = QuantumCircuit(x, y)
    # Write your code here:
 
    return qc

Please sign in to submit your answer.