Math
Fourier, a period, and a factor
Compare a peak with its neighbour. Then measure: a peak suggests a denominator, not a guaranteed factor. Ideal CPU simulation, 12 qubits; no noise or physical device. N=21 uses Q=128 < N²: reduced precision. Coprime bases only; otherwise gcd(a,N) already finds a factor.

What happens
Compare a peak with its neighbour. Then measure: a peak suggests a denominator, not a guaranteed factor.
Equations used in the module
Equations Q = 2^t; |ψ⟩ = Q^(-1/2) Σ_(x=0)^(Q−1) |x⟩|a^x mod N⟩ S_z(y) = Σ_(x: a^x mod N=z) exp(2πixy/Q); m_z = count(x in branch z) P(y given z) = |S_z(y)|²/(Q m_z); P(z)=m_z/Q P(y) = Σ_z |S_z(y)|²/Q²; Σ_y P(y)=1 y/Q ≈ p/d, 1 ≤ d < N; verify a^d mod N = 1 before factor extraction d even: h=a^(d/2) mod N; g−=gcd(h−1,N), g+=gcd(h+1,N) accept only 1<g−,g+<N and g−g+=N; h=±1 mod N is trivial N=15: t=8, work=4; N=21: t=7, work=5, Q=128<N² (reduced precision) ideal numerical state vector, 12 qubits; modular oracle is a basis permutation sample frequency=count/n; SE=sqrt(P(1−P)/n), n>0


