Problem Statement
Given an integer , implement an -qubit oracle on a quantum circuit .
The oracle acts on basis states , where and , as follows:
- If ,
- Otherwise,
Constraints
- Integers must be encoded by little-endian.
- Global phase is ignored in judge.
- The submitted code must follow the specified format:
from qiskit import QuantumCircuit, QuantumRegister
def solve(n: int) -> QuantumCircuit:
m, k = QuantumRegister(1), QuantumRegister(n)
qc = QuantumCircuit(m, k)
# Write your code here:
return qc
Hints
Open
- You can apply the quantum gate to all the qubits in the quantum register as follows:
from qiskit import QuantumRegister
k = QuantumRegister(n)
qc.g(k)
- You can apply the multi-controlled gate of any quantum gate as follows:
from qiskit.circuit.library import Gate
qc.append(Gate().control(n - 1), range(n))