A method for distilling a CCZ state, wherein the CCZ state is defined as the output of a CCZ gate applied to an input state | + + 0〉, the method comprising: preparing a register of qubits of a quantum computing device in a zero state, the register comprising three target qubits, a plurality of ancilla qubits and a plurality of stabilizer qubits; after preparing the register of qubits: performing, for each stabilizer qubit, an X gate on i) multiple ancilla qubits, or ii) multiple ancilla qubits and one of the three target qubits using the stabilizer qubit as a control; measuring the stabilizer qubits to determine respective stabilizer qubit states; after measuring the stabilizer qubits: performing, on each of the ancilla qubits, a Z 1/4 quantum gate and a Hadamard quantum gate; measuring the ancilla qubits to determine respective ancilla qubit states; after measuring the ancilla qubits, performing, conditioned on each determined ancilla qubit state, i) a NOT operation on a selected stabilizer qubit, or ii) a NOT operation on the selected stabilizer qubit and a Z gate on one or more of the three target qubits; subsequently, performing, on each target qubit of the three target qubits and conditioned on a determined state of a respective stabilizer qubit, a Z gate on the target qubit; and performing an X gate on each of the three target qubits to obtain the CCZ state encoded in the three target qubits. preparing a register of qubits of a quantum computing device in a zero state, the register comprising three target qubits, a plurality of ancilla qubits and a plurality of stabilizer qubits; after preparing the register of qubits: performing, for each stabilizer qubit, an X gate on i) multiple ancilla qubits, or ii) multiple ancilla qubits and one of the three target qubits using the stabilizer qubit as a control; measuring the stabilizer qubits to determine respective stabilizer qubit states; performing, for each stabilizer qubit, an X gate on i) multiple ancilla qubits, or ii) multiple ancilla qubits and one of the three target qubits using the stabilizer qubit as a control; measuring the stabilizer qubits to determine respective stabilizer qubit states; after measuring the stabilizer qubits: performing, on each of the ancilla qubits, a Z 1/4 quantum gate and a Hadamard quantum gate; measuring the ancilla qubits to determine respective ancilla qubit states; performing, on each of the ancilla qubits, a Z 1/4 quantum gate and a Hadamard quantum gate; measuring the ancilla qubits to determine respective ancilla qubit states; after measuring the ancilla qubits, performing, conditioned on each determined ancilla qubit state, i) a NOT operation on a selected stabilizer qubit, or ii) a NOT operation on the selected stabilizer qubit and a Z gate on one or more of the three target qubits; subsequently, performing, on each target qubit of the three target qubits and conditioned on a determined state of a respective stabilizer qubit, a Z gate on the target qubit; and performing an X gate on each of the three target qubits to obtain the CCZ state encoded in the three target qubits. performing, on each target qubit of the three target qubits and conditioned on a determined state of a respective stabilizer qubit, a Z gate on the target qubit; and performing an X gate on each of the three target qubits to obtain the CCZ state encoded in the three target qubits.