A3: Generate State 12(02n1)\frac{1}{\sqrt{2}}\lparen\ket{0}-\ket{2^{n}-1}\rparen I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Writer: ST12

Editorial

First, apply the Hadamard gate to the first qubit.

00000H(0)12(00000+10000)\begin{equation} \ket{0000 \cdots 0} \xrightarrow{H(0)} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1000 \cdots 0} \rparen \end{equation}

Next, we transform the state 10000\ket{1000 \cdots 0} to 11000\ket{1100 \cdots 0}. To achieve this, apply a controlled-X gate (CNOT gate) with the first qubit as the control bit and the second qubit as the target bit:

12(00000+10000)CX(0,1)12(00000+11000)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1000 \cdots 0} \rparen \xrightarrow{CX(0,1)} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1100 \cdots 0} \rparen \end{equation}

Similarly, to transform 11000\ket{1100 \cdots 0} to 11100\ket{1110 \cdots 0}, apply a controlled-X gate, with the first qubit as the control bit and the third qubit as the target bit.

12(00000+11000)CX(0,2)12(00000+11100)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1100 \cdots 0} \rparen \xrightarrow{CX(0,2)} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1110 \cdots 0} \rparen \end{equation}

By continuing to apply the controlled-X gate until the nn-th qubit is the target bit, we can prepare the quantum state ψ=12(0000+1111)\ket{\psi} = \frac{1}{\sqrt{2}} (\ket{00 \cdots 00} + \ket{11 \cdots 11}).

12(00000+11100)CX(0,3)CX(0,4)CX(0,n1)12(0...0+1...1)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0000 \cdots 0} + \ket{1110 \cdots 0} \rparen \xrightarrow{CX(0,3)} \, \xrightarrow{CX(0,4)} \cdots \xrightarrow{CX(0,n-1)} \frac{1}{\sqrt{2}} (\ket{0...0} + \ket{1...1}) \end{equation}

Finally, apply a Z gate to flip the phase of 1111\ket{11 \cdots 11}.

12(0...0+1...1)Z(0)12(0...01...1)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0...0} + \ket{1...1} \rparen \xrightarrow{Z(0)} \frac{1}{\sqrt{2}} \lparen \ket{0...0} - \ket{1...1} \rparen \end{equation}

Summarizing these operations, we obtain the following circuit:

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
 
 
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
 
    qc.h(0)
 
    for i in range(1, n):
        qc.cx(0, i)
 
    qc.z(0)
 
    return qc