B5: Modular Arithmetic I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 600

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 0k<L0 \leq k < L, the oracle OO satisfies

kn+1O(k+a) mod Ln+1.\ket{k}_{n+1} \xrightarrow{O} \ket{(k + a)\ \text{mod} \ L}_{n+1}.

Constraints

  • 1n101 \leq n \leq 10
  • 0a<L2n0 \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.