C3: Modular Arithmetic II

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

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 2n2n qubits.

For any pair of integers (x,y)(x, y) satisfying 0x<L0 \leq x < L and 0y<L0 \leq y < L, the oracle satisfies

xnynOxn(y+ax) mod Ln.\ket{x}_{n} \ket{y}_{n} \xrightarrow{O} \ket{x}_n \ket{(y + ax)\ \text{mod} \ L}_n.

Constraints

  • 1n51 \leq n \leq 5
  • 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, QuantumRegister
 
 
def solve(n: int, a: int, L: int) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(n + 1)
    qc = QuantumCircuit(x, y)
    # Write your code here:
 
    return qc

Hints

Open
  • You can consider the way to apply the solution of problem B5.
  • You can consider the following first, for any pair of integers (k,c)(k, c) satisfying 0k<L0 \leq k < L and 0c10 \leq c \leq 1.
c1knOc1(k+ca) mod Ln\ket{c}_1 \ket{k}_n \xrightarrow{O} \ket{c}_1 \ket{(k + ca)\ \text{mod} \ L}_n

Please sign in to submit your answer.