B5: Reflection Operator II

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given an integer nn. Implement the operation defined by the following matrix AA on a quantum circuit qc\mathrm{qc} with nn qubits:

A=2ψψIA = 2 \ket{\psi} \bra{\psi} - I

where II denotes the 2n×2n2^n \times 2^n identity matrix and ψ\ket{\psi} is defined by

ψ=12ni=02n1i.\ket{\psi} = \frac{1} {\sqrt{2^n}} \sum_{i=0}^{2^n-1} \ket{i}.

Constraints

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

Sample Input

  • n=2, ψ=14(00+10+01+11)n=2,\ \ket{\psi} = \frac{1}{\sqrt{4}} ( \ket{00} + \ket{10} + \ket{01} + \ket{11}): The matrix AA is calculated as follows.
A=2ψψI=(0.50.50.50.50.50.50.50.50.50.50.50.50.50.50.50.5)A = 2 \ket{\psi} \bra{\psi} - I = \begin{pmatrix} -0.5 & 0.5 & 0.5 & 0.5\\ 0.5 & -0.5 & 0.5 & 0.5\\ 0.5 & 0.5 & -0.5 & 0.5\\ 0.5 & 0.5 & 0.5 & -0.5 \end{pmatrix}

Please sign in to submit your answer.