B3: Generate State i(cosTi0+sinTi1)\bigotimes_i\lparen\cos{T_i}\ket{0}+\sin{T_i}\ket{1}\rparen

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given an integer nn and real numbers T0, T1, , Tn1T_0,\ T_1,\ \ldots,\ T_{n-1}. Implement the operation of preparing the state ψ\ket{\psi} from the zero state on a quantum circuit qc\mathrm{qc} with nn qubits.

The state ψ\ket{\psi} is defined as

ψ=(cosT00+sinT01)(cosT10+sinT11)(cosTn10+sinTn11).\ket{\psi}=(\cos T_0\ket{0}+\sin T_0\ket{1})(\cos T_1\ket{0}+\sin T_1\ket{1})\ldots(\cos T_{n-1}\ket{0}+\sin T_{n-1}\ket{1}).

Constraints

  • 1n101 \leq n \leq 10
  • π<Tiπ-\pi \lt T_i \leq \pi
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=3, (T0,T1,T2)=(π/6,π/3,π/2)n=3,\ (T_0, T_1, T_2) = (\pi / 6, \pi / 3, \pi / 2): Implemented circuit qc\mathrm{qc} should perform the following transformation.
000qc(cosπ60+sinπ61)(cosπ30+sinπ31)(cosπ20+sinπ21)=34001+14101+34011+34111\begin{align} \ket{000} \xrightarrow{\mathrm{qc}} &\left( \cos \frac{\pi}{6} \ket{0}+ \sin \frac{\pi}{6} \ket{1} \right) \left( \cos \frac{\pi}{3}\ket{0} + \sin \frac{\pi}{3} \ket{1} \right) \left( \cos \frac{\pi}{2} \ket{0} + \sin \frac{\pi}{2} \ket{1} \right) \nonumber\\ = &\frac{\sqrt{3}}{4} \ket{001} + \frac{1}{4} \ket{101} + \frac{3}{4} \ket{011} + \frac{\sqrt{3}}{4} \ket{111} \nonumber \end{align}

Please sign in to submit your answer.