Editorial
We focus on the fact that applying the operation of probelm B3 to the zero state results in the state .
When we express the quantum state as , we have:
From the properties of the adjoint matrix, we have:
This allows us to transform as follows:
Therefore, this problem can be solved by implementing the inverse circuit of the circuit implemented in B3, followed by implementing the circuit of B4, and then implementing the circuit of B3 again.
For the case where , the circuit diagram is shown below.
In the circuit diagram, Rotate_B3
represents the B3 circuit, Rotate_B3_dg
represents the inverse circuit of B3, and Reflect_B4
represents the B4 circuit.

Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
def reflect(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(range(n))
qc.append(ZGate().control(n - 1), range(n))
qc.x(range(n))
return qc
def rotate(n: int, T: list[float]) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range(n):
qc.ry(T[i] * 2, i)
return qc
def solve(n: int, T: list[float]) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.compose(rotate(n, T).inverse(), inplace=True)
qc.compose(reflect(n), inplace=True)
qc.compose(rotate(n, T), inplace=True)
return qc