Editorial
You can solve this problem by effectively using the Swap gate.
Let . You can obtain the desired quantum state by performing the following steps in order.
- Step 1: For , swap the th and th qubits.
- Step 2: For , swap the th and th qubits.
- Step 3: For , swap the th and th qubits.
Therefore, when , letting , the following state transitions hold:
As a result, you can solve this problem by following these steps.
The circuit diagram for is as follows.

Each step has circuit depth , so the total circuit depth is .
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
L = n + 1
qc = QuantumCircuit(L)
for i in range(L.bit_length()):
for j in range(0, L - (2 ** i), 2 ** (i + 1)):
qc.swap(j, j + (2 ** i))
return qc