B5: Modular Arithmetic I

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 600 points

Problem Statement

You are given integers nn, aa and LL.

Implement an oracle OO satisfying the following transition on a quantum circuit qc\mathrm{qc} with n+1n+1 qubits.

For arbitrary integer kk satisfying 0≤k<L0 \leq k < L, the operation satisfies

∣k⟩n+1→O∣(k+a) mod L⟩n+1\ket{k}_{n+1} \xrightarrow{O} \ket{(k + a)\ \text{mod} \ L}_{n+1}

Constraints

  • 1≤n≤101 \leq n \leq 10
  • 0≤a<L≤2n0 \leq a < L \leq 2^n
  • Global phase is ignored in judge.
  • Integers must be encoded by little-endian.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int, a: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
 
    return qc

Hints

Open
  • You can consider the way to apply the solution of problem B4.
  • You can add extra qubits if needed.

Please sign in to submit your answer.