B3: Controlled Constant Addition

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Problem Statement

You are given integers nn and aa.

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

For any pair of integers (k,c)(k, c) satisfying 0k<2n0 \leq k < 2^n and 0c10 \leq c \leq 1, the oracle satisfies

knc1O(k+ca)mod2nnc1.\ket{k}_n \ket{c}_1 \xrightarrow{O} \ket{(k + ca) \bmod 2^n}_n \ket{c}_1.

Constraints

  • 1n101 \leq n \leq 10
  • 0a<2n0 \leq a < 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) -> QuantumCircuit:
    k, c = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(k, c)
    # Write your code here:
 
    return qc

Hints

Open
  • You can consider the following oracle without cc first.
knO(k+a)mod2nn\ket{k}_n \xrightarrow{O} \ket{(k + a) \bmod 2^n}_n

Please sign in to submit your answer.