The Order-Finding Subroutine

Suppose you are handed an integer aa coprime to NN. You are asked for the smallest positive integer rr such that ar≡1(modN)a^r \equiv 1 \pmod N. This is the order-finding problem. No classical algorithm is known that solves it in time polynomial in log⁡N\log N. Every known classical approach either factors NN first or searches exponentially many candidate exponents. The best general-purpose classical methods run in sub-exponential but still super-polynomial time. Order finding looks like a narrow number-theoretic curiosity. But it is the computational heart of Shor's Factoring Algorithm. Once you can find multiplicative orders efficiently, factoring large integers becomes tractable. So does breaking RSA-style public-key cryptography. This single subroutine is the reason quantum computers threaten a large fraction of deployed internet cryptography. That is why every major standards body now tracks progress toward fault-tolerant machines. Such machines would need to run it at cryptographic scale. The quantum solution combines two ideas you should already have in hand. The first is Quantum Phase Estimation, which extracts eigenvalue phases of a unitary to high precision. The second is the classical theory of Continued Fractions, which recovers exact rationals from their decimal (or binary) approximations. The trick is to build a unitary UU whose eigenphases encode rr. Then run phase estimation to estimate one such phase. Finally, use a continued-fraction expansion to pull the integer rr out of that noisy estimate. This article gives the complete circuit-level construction. It covers the modular exponentiation unitary, the phase estimation wrapper, and the classical post-processing. It also gives a full correctness and complexity analysis. This analysis shows why O((log⁡N)3)O((\log N)^3) quantum gates (with efficient modular exponentiation) suffice. Classical methods, by contrast, need far more.

Key takeaways
  • Order finding asks for the smallest r>0r>0 with ar≡1(modN)a^r \equiv 1 \pmod N; classically hard, quantumly efficient.
  • The unitary Ua∣x⟩=∣ax  N⟩U_a\vert x\rangle = \vert ax \bmod N\rangle has eigenphases that are exact multiples of 1/r1/r.
  • Quantum phase estimation on UaU_a yields a 2n2n-bit approximation to s/rs/r for a random integer ss.
  • The continued-fraction expansion of that approximation recovers s/rs/r in lowest terms in O(n3)O(n^3) classical time.
  • Repeating O(log⁡log⁡r)O(\log\log r) times and taking the LCM of candidate denominators finds rr with high probability.
  • This subroutine, wrapped in modular exponentiation, is exactly the quantum core of Shor's factoring algorithm.
The core insight

Order finding works because the periodicity of modular exponentiation shows up as an exact eigenphase of a unitary, which quantum phase estimation can read out and continued fractions can decode into the period itself.

The idea

Fix NN and an integer aa with gcd⁡(a,N)=1\gcd(a,N)=1. The multiplicative order of aa modulo NN, written ordN(a)\mathrm{ord}_N(a), is the smallest positive integer rr such that ar≡1(modN)a^r \equiv 1 \pmod N. Such an rr always exists (by Euler's theorem, r≤φ(N)r \le \varphi(N)), and the sequence a0,a1,a2,…(modN)a^0, a^1, a^2, \dots \pmod N is periodic with period exactly rr. Order finding is precisely the task of computing this period given aa and NN. The key structural fact is this: consider the unitary operator UaU_a acting on the nn-qubit register of integers mod NN (padded up to dimension 2n≥N2^n \ge N) defined by

Ua∣x⟩=∣ax  N⟩for 0≤x<N,U_a \vert x \rangle = \vert a x \bmod N \rangle \quad \text{for } 0 \le x < N,

and acting as the identity (or arbitrarily, as long as it stays unitary) on basis states ∣x⟩\vert x\rangle with x≥Nx \ge N. Because aa is invertible mod NN, this map is a permutation of {0,…,N−1}\{0,\dots,N-1\}, hence UaU_a is a genuine unitary (a permutation matrix) on that subspace. Since ar≡1a^r \equiv 1, we have Uar=IU_a^r = I on that subspace, so every eigenvalue of UaU_a restricted there is an rr-th root of unity: e2πik/re^{2\pi i k/r} for k=0,1,…,r−1k = 0, 1, \dots, r-1. The problem of finding rr becomes the problem of reading off one of these eigenphases and recognizing the denominator rr hiding inside it. Phase estimation is built exactly for this: given a unitary UU and an eigenstate ∣ψ⟩\vert\psi\rangle with U∣ψ⟩=e2πiφ∣ψ⟩U\vert\psi\rangle = e^{2\pi i \varphi}\vert\psi\rangle, it produces an estimate of φ\varphi. The catch is that we do not have direct access to a single eigenstate of UaU_a — we can only prepare basis states, which are superpositions of eigenstates. It turns out this is not a problem: preparing ∣1⟩\vert 1\rangle (or any convenient computational basis state coprime-compatible with the cycle structure) as the phase-estimation input state is an equal superposition over the eigenstates of UaU_a with a specific, uniform distribution of eigenvalues e2πik/re^{2\pi i k/r}, k=0,…,r−1k=0,\dots,r-1. Phase estimation on this input therefore collapses, upon measurement, to a random kk and reports (an estimate of) k/rk/r. The remaining work is to recover rr from noisy knowledge of k/rk/r, and that is exactly what the continued fraction algorithm does: given a good rational approximation to k/rk/r, it reconstructs k/rk/r in lowest terms, from which rr is read off as the denominator (after ruling out common-factor degeneracies).

How it works

The full algorithm has a quantum stage (phase estimation on modular exponentiation) and a classical stage (continued fractions plus a repeat-and-verify loop).

Setup. Let NN be the modulus, n=⌈log⁡2N⌉n = \lceil \log_2 N \rceil so an nn-qubit register can hold any residue mod NN. Choose the phase-estimation precision register to have t=2n+1t = 2n + 1 qubits (enough bits to make continued-fraction recovery unique with high probability; the "+1" is a small safety margin used in the standard analysis).

Step 1 — Prepare registers. Initialize a tt-qubit control register in ∣0⟩⊗t\vert 0\rangle^{\otimes t} and an nn-qubit target register in ∣1⟩\vert 1\rangle (a convenient basis state, since 11 generates a cyclic subgroup interaction with every aa).

Step 2 — Superposition on the control register. Apply Hadamard to every control qubit, producing

12t∑j=02t−1∣j⟩∣1⟩.\frac{1}{\sqrt{2^t}} \sum_{j=0}^{2^t - 1} \vert j \rangle \vert 1 \rangle.

Step 3 — Controlled modular exponentiation. Apply the unitary

∣j⟩∣y⟩  ⟼  ∣j⟩∣ajy  N⟩,\vert j \rangle \vert y \rangle \; \longmapsto \; \vert j \rangle \vert a^j y \bmod N \rangle,

implemented as a cascade of controlled-Ua2iU_a^{2^i} operations (the standard phase-estimation trick), each conditioned on one bit of jj: qubit ii of the control register controls an application of Ua2iU_a^{2^i}, i.e. "multiply the target register by a2i  Na^{2^i} \bmod N if that control bit is 1." This is exactly repeated modular squaring — the same fast-exponentiation trick used classically — realized reversibly as a quantum circuit. The result is

12t∑j=02t−1∣j⟩∣aj  N⟩.\frac{1}{\sqrt{2^t}} \sum_{j=0}^{2^t-1} \vert j \rangle \vert a^j \bmod N \rangle.

Step 4 — Inverse QFT on the control register. This is the phase-estimation readout step: apply QFT−1\mathrm{QFT}^{-1} to the tt control qubits and measure them in the computational basis, yielding a tt-bit integer yy.

Step 5 — Classical continued-fraction recovery. Compute φ=y/2t\varphi = y / 2^t and expand it as a continued fraction; take successive convergents pi/qip_i/q_i until you find one with qi<Nq_i < N that is a strong candidate for s/rs/r in lowest terms. Output the denominator qiq_i as a candidate order rcandr_{\text{cand}}.

Step 6 — Verify and repeat. Check arcand  N1a^{r_{\text{cand}}} \bmod N \stackrel{?}{=} 1. If not (or if gcd⁡(s,r)>1\gcd(s, r) > 1 made qiq_i a proper divisor of rr rather than rr itself), repeat the whole procedure a small number of times and take the least common multiple of the candidate denominators obtained, then verify that LCM against aa. ``` function ORDER-FIND(a, N): n ← ceil(log2(N)) t ← 2n + 1 # precision register size repeat up to M = O(log log N) times:

# --- quantum phase estimation stage --- prepare control register C of t qubits in |0...0> prepare target register T of n qubits in |1> apply H to every qubit of C for i in 0 .. t-1: apply controlled-U_a^(2^i) with control = C[i], target = T

# U_a^(2^i) |y> = |a^(2^i) * y mod N>, realized via

# repeated modular squaring, computed reversibly apply inverse-QFT to C measure C, obtaining integer y in [0, 2^t - 1]

# --- classical post-processing stage --- phi ← y / 2^t (p, q) ← BEST-CONVERGENT(phi, max_denominator = N)

# continued-fraction expansion of phi,

# returns the convergent p_i/q_i with q_i < N

# closest to phi candidates.append(q) r ← LCM(candidates) if a^r mod N == 1 and r > 0: return r else: return FAIL # retry ORDER-FIND from scratch ``` ``` function BEST-CONVERGENT(phi, max_denominator):

# standard continued fraction expansion of phi a0 ← floor(phi) terms ← [a0] x ← phi - a0 p_prev, q_prev ← 1, 0 p_cur, q_cur ← a0, 1 while q_cur <= max_denominator and x != 0: x ← 1 / x ai ← floor(x) p_next ← ai p_cur + p_prev q_next ← ai q_cur + q_prev if q_next > max_denominator: break p_prev, q_prev ← p_cur, q_cur p_cur, q_cur ← p_next, q_next x ← x - ai return (p_cur, q_cur) ``` The controlled-Ua2iU_a^{2^i} gates are the only "arithmetic" part of the circuit: each is a reversible modular multiplication by a fixed classical constant a2i  Na^{2^i} \bmod N (itself precomputed classically, once, by repeated squaring), implemented with reversible adders and reversible modular reduction circuits — standard building blocks with known polynomial-size constructions.

Figure
Order-finding circuit: phase estimation wrapped around controlled modular exponentiation
Control register |0…0⟩ (t qubits) c₀ c₁ c_{t-1} Target register |1⟩ (n qubits) H H H U_a^1 U_a^2 U_a^(2^{t-1}) QFT⁻¹ measure→y → y/2^t → CF → r Each controlled-U_a^(2^i) multiplies the target by a^(2^i) mod N, reversibly.

Complexity & correctness

Correctness — why the phases are exact multiples of 1/r1/r. Because UaU_a restricted to the cyclic set {a0,a1,…,ar−1}  N\{a^0, a^1, \dots, a^{r-1}\} \bmod N is a cyclic permutation of order rr, its eigenvalues on the span of these basis states are exactly the rr-th roots of unity e2πik/re^{2\pi i k / r} for k=0,…,r−1k = 0, \dots, r-1, with eigenvectors

∣uk⟩=1r∑j=0r−1e−2πikj/r∣aj  N⟩.\vert u_k \rangle = \frac{1}{\sqrt r} \sum_{j=0}^{r-1} e^{-2\pi i kj/r} \vert a^j \bmod N \rangle.

A direct check confirms Ua∣uk⟩=e2πik/r∣uk⟩U_a \vert u_k\rangle = e^{2\pi i k/r}\vert u_k\rangle. The initial state ∣1⟩\vert 1 \rangle decomposes as the equal-weight superposition ∣1⟩=1r∑k=0r−1∣uk⟩\vert 1\rangle = \frac{1}{\sqrt r}\sum_{k=0}^{r-1} \vert u_k\rangle. Running phase estimation on this input is, by linearity, equivalent to running it on a uniformly random ∣uk⟩\vert u_k\rangle: the measured control register collapses to an estimate of k/rk/r for a uniformly random k∈{0,…,r−1}k \in \{0, \dots, r-1\}.

Why continued fractions recover rr. Phase estimation with tt control qubits produces yy such that y/2ty/2^t approximates k/rk/r to within 1/2t1/2^t with probability at least ≈4/π2\approx 4/\pi^2 (the standard phase estimation error bound), and with the choice t=2n+1≥2log⁡2N+1t = 2n+1 \ge 2\log_2 N + 1, the approximation error satisfies

∣y2t−kr∣<12r2,\left| \frac{y}{2^t} - \frac{k}{r} \right| < \frac{1}{2r^2},

because r<N≤2nr < N \le 2^n implies 2r2<2⋅22n≤2t2r^2 < 2 \cdot 2^{2n} \le 2^t. A classical theorem on continued fractions guarantees: if ∣φ−p/q∣<1/(2q2)|\varphi - p/q| < 1/(2q^2) for coprime integers p,qp, q, then p/qp/q is necessarily one of the convergents of the continued-fraction expansion of φ\varphi. Since k/rk/r (in lowest terms, dividing out gcd⁡(k,r)\gcd(k,r)) satisfies this bound, the convergent-search step is guaranteed to encounter it. The algorithm scans convergents with denominator <N< N and returns the appropriate one — this recovers s/r0s/r_0 where r0=r/gcd⁡(k,r)r_0 = r/\gcd(k,r), a divisor of rr, not necessarily rr itself.

Why repetition fixes the gcd⁡(k,r)>1\gcd(k,r) > 1 issue. If kk happens to share a common factor with rr, the recovered denominator r0r_0 is a proper divisor of rr, not rr. However, kk is uniform on {0,…,r−1}\{0,\dots,r-1\}, and it is a standard fact that a uniformly random kk satisfies gcd⁡(k,r)=1\gcd(k, r) = 1 with probability at least Ω(1/log⁡log⁡r)\Omega(1/\log\log r) (via bounds on the density of integers with few or large prime factors relative to φ(r)/r\varphi(r)/r type arguments — concretely, the probability that k/rk/r reduces to something with denominator exactly rr is bounded below by a constant fraction over O(log⁡log⁡r)O(\log\log r) independent trials in expectation). Running the quantum stage O(log⁡log⁡N)O(\log\log N) times and taking the LCM of the resulting candidate denominators drives the failure probability down to an arbitrarily small constant, and a final classical check ar  N=1a^{r} \bmod N = 1 certifies success — false accepts are impossible since verification is exact.

Time complexity.

  • Quantum circuit size: t=O(n)t = O(n) control qubits, and tt controlled modular-exponentiation gates, each a reversible modular multiplication circuit of size O(n2)O(n^2) (schoolbook) or O(nlog⁡nlog⁡log⁡n)O(n \log n \log\log n) (fast multiplication), giving total gate count O(n3)O(n^3) (or O(n2log⁡nlog⁡log⁡n)O(n^2 \log n \log \log n) with fast arithmetic).
  • Inverse QFT: O(t2)=O(n2)O(t^2) = O(n^2) gates (or O(nlog⁡n)O(n \log n) with the approximate QFT).
  • Classical continued-fraction expansion: O(n)O(n) Euclidean-algorithm-style steps, each with O(n2)O(n^2)-time big-integer arithmetic (or O(nlog⁡n)O(n \log n) with fast algorithms), so O(n3)O(n^3) total — negligible compared to the quantum circuit.
  • Repetitions: O(log⁡log⁡N)=O(log⁡n)O(\log \log N) = O(\log n), an essentially negligible multiplicative overhead.

Overall, order finding runs in O(n3)O(n^3) elementary gates (n=log⁡2Nn = \log_2 N), i.e. polynomial in log⁡N\log N — exponentially faster than the best known classical algorithms, which require time super-polynomial in log⁡N\log N (subexponential, roughly LL-notation complexity like general number-field-sieve-style bounds for related problems, though order finding specifically has no known polynomial classical algorithm and no proof of hardness either — it is an unproven, empirically robust separation).

Space complexity. O(n)O(n) qubits: t=O(n)t = O(n) for the control register and nn for the target register, plus O(n)O(n) ancilla qubits for the reversible arithmetic circuits (garbage collection of ancillas is possible via standard reversible-computation techniques, keeping the total workspace linear in nn).

Honest tradeoffs. The polynomial gate count hides a large constant: fault-tolerant modular exponentiation on cryptographically-sized NN (2048-bit RSA moduli) requires millions of logical qubit-operations and, with current error-correction overheads, potentially billions of physical gate operations. The algorithm is probabilistic — repetition and verification are mandatory, not optional — and its correctness relies on classical arithmetic (GCD, LCM, verification) being cheap and exact, which they are, but errors in the quantum part (decoherence, gate infidelity) are not corrected by the classical post-processing and must be handled by Quantum Error Correction beneath this algorithm.

Worked example

Take N=21N = 21, a=2a = 2. First check gcd⁡(2,21)=1\gcd(2, 21) = 1: yes. The true order is found by direct computation:

jj2j  212^j \bmod 21
01
12
24
38
416
511
61 (cycle repeats)

So r=6r = 6: the true order of 22 mod 2121 is 66. Now trace the quantum algorithm conceptually. We need n=⌈log⁡221⌉=5n = \lceil \log_2 21 \rceil = 5 qubits for the target register, and t=2n+1=11t = 2n+1 = 11 control qubits, giving 211=20482^{11} = 2048 possible measurement outcomes for yy. The eigenphases of U2U_2 on the cycle {1,2,4,8,16,11}\{1,2,4,8,16,11\} are e2πik/6e^{2\pi i k/6} for k=0,…,5k = 0,\dots,5. Suppose the measurement collapses to k=5k = 5 (a case with gcd⁡(5,6)=1\gcd(5,6)=1, the "clean" case). Phase estimation ideally would give y/211≈5/6=0.83‾y/2^{11} \approx 5/6 = 0.8\overline{3}. Concretely 5/6⋅2048=1706.675/6 \cdot 2048 = 1706.67, so a likely measured value is y=1707y = 1707, giving

φ=1707/2048=0.833496…\varphi = 1707/2048 = 0.833496\dots

Run the continued fraction expansion of φ=1707/2048\varphi = 1707/2048:

stepinteger partremainderconvergent pi/qip_i/q_i
0a0=0a_0 = 01707/20481707/20480/10/1
1a1=⌊2048/1707⌋=1a_1 = \lfloor 2048/1707\rfloor = 11/11/1
2a2=⌊1707/341⌋=5a_2 = \lfloor 1707/341\rfloor = 55/65/6
3a3=⌊341/2⌋=170a_3 = \lfloor 341/2 \rfloor = 170(denominator jumps past N=21N=21, stop)

The first convergent with denominator <21< 21 that closely matches is 5/65/6, obtained at step 2, exactly the true k/r=5/6k/r = 5/6. The algorithm outputs candidate denominator q=6q = 6.

Verification. Check 26  21=64  21=12^6 \bmod 21 = 64 \bmod 21 = 1. ✓ Success — r=6r = 6 is confirmed on the first attempt, no repetition needed. Now consider a "unlucky" branch: suppose instead the measurement had collapsed to k=2k = 2, where gcd⁡(2,6)=2\gcd(2,6) = 2. Then k/r=2/6=1/3k/r = 2/6 = 1/3 in lowest terms, and the continued-fraction search returns q=3q = 3, a proper divisor of the true order. A single run reports the wrong order (23  21=8≠12^3 \bmod 21 = 8 \ne 1, so the verification step would actually catch this directly!). This is exactly why Step 6 (verify, and if needed repeat and take LCMs) exists: with two independent runs, one landing on k=5k=5 (denominator 6) and another on k=4k=4 (giving 2/32/3 in lowest terms, denominator 3), lcm(6,3)=6\mathrm{lcm}(6,3) = 6 recovers the correct order even if a single run alone was ambiguous.

Common pitfalls & traps

PitfallWhat goes wrongFix
Using too few control qubitstt too small means y/2ty/2^t doesn't approximate k/rk/r tightly enough for the continued-fraction theorem to applyUse t≥2⌈log⁡2N⌉+1t \ge 2\lceil \log_2 N\rceil + 1
Forgetting to verify the candidate rrA gcd⁡(k,r)>1\gcd(k,r)>1 collapse silently returns a proper divisor as if it were rrAlways check arcand  N=1a^{r_{\text{cand}}} \bmod N = 1 before accepting
Treating a single run as sufficientSuccess probability per run is only Ω(1/log⁡log⁡r)\Omega(1/\log\log r), not highRepeat O(log⁡log⁡N)O(\log\log N) times and take LCM of candidates
Confusing the eigenphase k/rk/r with the measured bitstring yy directlyyy is an integer in [0,2t)[0, 2^t), not the phase itself; skipping the division by 2t2^t breaks everything downstreamAlways compute φ=y/2t\varphi = y/2^t before continued-fraction expansion
Implementing Ua2iU_a^{2^i} naively as ii sequential applications of UaU_aBlows up circuit depth to O(2t)O(2^t) instead of O(t)O(t)Precompute a2i  Na^{2^i} \bmod N classically once, build a single modular-multiplication-by-constant circuit per control bit
Choosing aa not coprime to NNUaU_a is not a bijection on {0,…,N−1}\{0,\dots,N-1\}, hence not unitary in the intended wayCheck gcd⁡(a,N)=1\gcd(a,N)=1 first (if not, gcd⁡(a,N)\gcd(a,N) is itself a nontrivial factor of NN — useful in the factoring context but breaks order finding as stated)

Pioneers & history

Origins · 1 minPeter Williston Shor and how this was discovered
PW
Peter Williston Shor
born 1959 · Bell Labs, 1994

Peter Shor devised the full factoring algorithm — of which order finding is the quantum core — while at Bell Laboratories, building directly on prior quantum Fourier transform and phase estimation ideas developed by Coppersmith, Deutsch, and Simon. His 1994 result is widely regarded as the single most consequential theoretical result in quantum computing, since it gave the first strong evidence that a working quantum computer could break the cryptographic assumptions underlying RSA.

History
1976
— Diffie and Hellman introduce public-key cryptography, later underpinning RSA's reliance on the hardness of factoring.
1985
— Deutsch formalizes the quantum Turing machine and the notion of quantum parallelism.
1994
— Shor publishes the factoring algorithm, embedding order finding via phase estimation and continued fractions.
1996
— Kitaev reformulates phase estimation more generally, clarifying the eigenvalue-estimation view used to teach order finding today.
2001
— IBM researchers demonstrate a small-scale experimental factorization of 15 using a 7-qubit NMR system, exercising the order-finding subroutine directly.

Where this matters

Order finding is not deployed in production systems today, because no quantum computer yet has enough error-corrected qubits to run it on cryptographically relevant moduli — but its threat model already shapes real infrastructure decisions. Standards bodies such as NIST have run multi-year competitions to select post-quantum cryptographic algorithms (lattice-based schemes like Kyber and Dilithium) precisely because Shor's algorithm, built on this subroutine, would break RSA and elliptic-curve cryptography outright given a sufficiently large fault-tolerant quantum computer. Financial institutions, governments, and browser vendors are actively migrating TLS and VPN protocols to hybrid classical/post-quantum schemes today, years before such a machine might exist, as a direct consequence of this algorithm's existence. On the research side, order finding (and its close cousin, the abelian Hidden Subgroup Problem) is the canonical example used to teach the power of the quantum Fourier transform, and every subsequent quantum algorithm with exponential speedups over classical methods for algebraic problems — discrete logarithm, Pell's equation, certain hidden shift problems — reuses the same phase-estimation-plus-continued-fractions template. Experimental groups building superconducting, trapped-ion, and photonic quantum processors use small-scale factoring demonstrations (factoring 15, 21, and similar small numbers) as benchmark tasks that exercise controlled modular arithmetic, phase estimation, and measurement — making order finding one of the most-implemented "hard" quantum subroutines in the experimental literature, even at toy scale.

Ask the tutor: How does the choice of aa affect the probability that order finding succeeds on a given attempt, and why does averaging over random aa matter for the factoring reduction?

Why must aa and NN be coprime for order finding to make sense?

If gcd⁡(a,N)=d>1\gcd(a, N) = d > 1, then aa is not invertible modulo NN, so the map x↦ax  Nx \mapsto ax \bmod N is not a bijection on {0,…,N−1}\{0, \dots, N-1\} — some residues have no preimage. The operator UaU_a as defined would then fail to be unitary on that subspace, because unitary matrices must be invertible (norm-preserving bijections), and a non-injective linear map cannot be norm-preserving on the full space. Practically, if gcd⁡(a,N)>1\gcd(a,N) > 1 is discovered first, that GCD is already a nontrivial factor of NN, so order finding is unnecessary — this is one of the branches Shor's algorithm checks before invoking the quantum subroutine at all.

Why does the algorithm use t≈2n+1t \approx 2n+1 control qubits rather than just nn?

Phase estimation accuracy scales with the number of control qubits: with tt qubits, the estimate lands within 1/2t1/2^t of the true phase with high probability. The continued-fraction recovery theorem requires the approximation error to be strictly less than 1/(2r2)1/(2r^2), and since r<N≤2nr < N \le 2^n, this demands 2t2^t to be comparably larger than r2≈22nr^2 \approx 2^{2n}. Choosing t=2n+1t = 2n+1 gives exactly this margin. Using only nn qubits would give resolution 1/2n1/2^n, far too coarse to distinguish nearby fractions k/rk/r once rr approaches NN in size.

What happens if the algorithm fails — does it give a wrong answer or detect failure?

It detects failure, and this is a key design feature. The final classical step checks arcand  N1a^{r_{\text{cand}}} \bmod N \stackrel{?}{=} 1 exactly, using ordinary modular exponentiation, which is cheap and completely reliable classically. If the check fails, the algorithm does not output a wrong answer — it reports failure and retries the entire quantum-plus-classical pipeline. This makes order finding a Monte Carlo algorithm with zero-error verification: any output it does return is guaranteed correct, and only the running time is randomized.

How does order finding connect to factoring NN, foreshadowing Shor's algorithm?

If r=ordN(a)r = \mathrm{ord}_N(a) is even, and ar/2≢−1(modN)a^{r/2} \not\equiv -1 \pmod N, then gcd⁡(ar/2−1,N)\gcd(a^{r/2}-1, N) and gcd⁡(ar/2+1,N)\gcd(a^{r/2}+1, N) are (with high probability over random choice of aa) nontrivial factors of NN. This follows because ar−1=(ar/2−1)(ar/2+1)≡0(modN)a^r - 1 = (a^{r/2}-1)(a^{r/2}+1) \equiv 0 \pmod N, but neither factor alone is ≡0\equiv 0, forcing NN's prime factors to split between the two GCDs. Order finding is thus the one genuinely quantum ingredient; everything else in factoring is classical number theory wrapped around it.

Could this algorithm be run on a small quantum computer today for real cryptographic moduli?

No. Factoring a 2048-bit RSA modulus would require an n≈2048n \approx 2048-bit target register, roughly t≈4097t \approx 4097 control qubits, and reversible modular exponentiation circuits with millions of logical gates, all executed with error rates low enough to survive that many operations. Current quantum hardware, even with error correction, is many orders of magnitude away from this scale. Demonstrations to date have factored numbers like 15 or 21 — instructive but cryptographically meaningless — precisely to exercise this subroutine's circuit structure at toy scale.

Is there a known proof that no classical algorithm can solve order finding efficiently?

No such proof exists. Order finding's classical hardness is a widely believed but unproven conjecture, closely tied to the conjectured hardness of integer factorization — the two problems are polynomial-time equivalent in a certain sense (an efficient order-finding oracle yields efficient factoring, and vice versa for many practical cases). No lower bound rules out a clever classical polynomial-time algorithm; the belief in hardness rests on decades of failed attempts and the problem's deep structural similarity to factoring and discrete logarithm, both cornerstones of modern cryptography.

Why is the input state ∣1⟩|1\rangle used rather than an explicit eigenstate of UaU_a?

Explicit eigenstates ∣uk⟩\vert u_k\rangle are complex superpositions over the entire cycle {a0,…,ar−1}\{a^0, \dots, a^{r-1}\} and are just as hard to prepare directly as the answer itself — you would need to know rr to build them. The state ∣1⟩\vert 1\rangle is trivial to prepare and happens to equal the uniform superposition of all ∣uk⟩\vert u_k\rangle with equal amplitude 1/r1/\sqrt r. Phase estimation then effectively samples a uniformly random eigenstate for free, at the cost of only needing repetition to handle the cases where the sampled kk shares a factor with rr.

Before this

Where this leads