B3: Less Than Oracle I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Problem Statement

You are given integers nn and LL. Implement the oracle OO on a quantum circuit qc\mathrm{qc} with nn qubits, which multiplies all the probability amplitudes aia_i of 0, 1, ... L1\ket{0},\ \ket{1},\ ...\ \ket{L-1} by 1-1.

Constraints

  • 1n51 \leq n \leq 5
  • 1L2n1 \leq L \leq 2^n
  • Global phase is ignored in judge.
  • Integers must be encoded by little-endian notation, i.e., 100=1001\ket{100} = 1 \neq \ket{001}.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=2, L=3n = 2,\ L=3: The implemented oracle OO should perform the following transformation.
14(00+10+01+11)O14(001001+11)\frac{1}{\sqrt{4}} (\ket{00} + \ket{10} + \ket{01} + \ket{11}) \xrightarrow{O} \frac{1}{\sqrt{4}} (-\ket{00} - \ket{10} - \ket{01} + \ket{11})

Hints

Open
  • You can apply the multi-controlled gate of any quantum gate GateGate as follows:
from qiskit.circuit.library import Gate
 
qc.append(Gate().control(n - 1), range(n))

Please sign in to submit your answer.