Math 2.0

Computer science Randomized, circuit, counting and interactive complexity Theorem

Shor's algorithm

Builds on Quantum complexity class BQPInteger factorizationOrder of an element

Statement

There is a quantum algorithm with the following property. Given an integer N≥2N \ge 2 with nn binary digits, it outputs the prime factorization of NN with probability at least 2/32/3. Its running time is bounded by a polynomial in nn.

In particular, the decision version of integer factorization lies in BQP.

Remarks

The algorithm reduces factoring to order finding. For an odd NN that is not a prime power, pick a random aa with gcd⁡(a,N)=1\gcd(a, N) = 1 and let rr be the order of aa modulo NN. With probability at least 1/21/2, rr is even and ar/2≢−1(modN)a^{r/2} \not\equiv -1 \pmod N, and then gcd⁡(ar/2−1,N)\gcd(a^{r/2} - 1, N) is a nontrivial factor of NN. The quantum part finds rr: it prepares a superposition over exponents xx, computes ax mod Na^x \bmod N, applies the quantum Fourier transform, and measures. The exponents range over 0≤x<2m0 \le x < 2^m with N2≤2m<2N2N^2 \le 2^m < 2N^2. The measured value is close to a multiple of 2m/r2^{m}/r, and rr is recovered from it with continued fractions.

Example: for N=15N = 15 and a=7a = 7, the powers of 77 modulo 1515 are 7,4,13,17, 4, 13, 1, so r=4r = 4. Then 72=497^2 = 49 and gcd⁡(48,15)=3\gcd(48, 15) = 3, gcd⁡(50,15)=5\gcd(50, 15) = 5, which gives 15=3⋅515 = 3 \cdot 5.

With schoolbook arithmetic the algorithm uses O(n3)O(n^3) gates, the cost being dominated by modular exponentiation. The same method computes discrete logarithms in polynomial time.

Going deeper

For a student

The classical part is elementary number theory: a period of ax mod Na^x \bmod N gives a square root of 11 modulo NN, and a nontrivial square root of 11 yields a factor. The quantum Fourier transform is the quantum version of the discrete Fourier transform, and it turns periodicity into peaks of probability. The method generalizes to the hidden subgroup problem for finite abelian groups. It breaks RSA, Diffie–Hellman and elliptic curve cryptography, which motivates post-quantum cryptography.

Reading path

To understand this page from the ground up, read these 35 pages in order. The foundations come first.

Show the path as a graph
Composite number, concept, no evidence levelComposite numberconceptDivisibility, definition, no evidence levelDivisibilitydefinitionEuler's totient function, concept, no evidence levelEuler's totient funct…conceptGroup, concept, no evidence levelGroupconceptModular exponentiation, concept, no evidence levelModular exponentiationconceptMultiplicative order, concept, no evidence levelMultiplicative orderconceptOrder of an element, concept, no evidence levelOrder of an elementconceptPolynomial ring, concept, no evidence levelPolynomial ringconceptPrime factorization, concept, no evidence levelPrime factorizationconceptPrime number, concept, no evidence levelPrime numberconceptQuantum complexity class BQP, concept, no evidence levelQuantum complexity cl…conceptQuotient ring, concept, no evidence levelQuotient ringconceptCongruence modulo n, definition, no evidence levelCongruence modulo ndefinitionGreatest common divisor, definition, no evidence levelGreatest common divis…definitionPrime number, definition, no evidence levelPrime numberdefinitionRing, definition, no evidence levelRingdefinitionModular multiplicative inverse, definition, no evidence levelModular multiplicativ…definitionCoprime integers, definition, no evidence levelCoprime integersdefinitionFermat's little theorem, statement, no evidence levelFermat's little theor…statementEuclid's lemma, statement, no evidence levelEuclid's lemmastatementExistence of a prime divisor, statement, no evidence levelExistence of a prime …statementPrimality test, concept, no evidence levelPrimality testconceptPrime factorization, definition, no evidence levelPrime factorizationdefinitionCharacteristic of a ring, definition, no evidence levelCharacteristic of a r…definitionCommutative ring, definition, no evidence levelCommutative ringdefinitionEuler's totient function, definition, no evidence levelEuler's totient funct…definitionMiller–Rabin primality test, concept, no evidence levelMiller–Rabin primalit…conceptExistence of prime factorization, statement, no evidence levelExistence of prime fa…statementFreshman's dream, statement, no evidence levelFreshman's dreamstatementEuler's theorem, statement, no evidence levelEuler's theoremstatementFundamental theorem of arithmetic, statement, no evidence levelFundamental theorem o…statementAKS primality test, statement, no evidence levelAKS primality teststatementRSA cryptosystem, example, no evidence levelRSA cryptosystemexampleInteger factorization, problem, no evidence levelInteger factorizationproblemShor's algorithm, statement, no evidence levelShor's algorithmstatement
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Composite number concept
  2. Divisibility definition
  3. Euler's totient function concept
  4. Group concept
  5. Modular exponentiation concept
  6. Multiplicative order concept
  7. Order of an element concept
  8. Polynomial ring concept
  9. Prime factorization concept
  10. Prime number concept
  11. Quantum complexity class BQP concept
  12. Quotient ring concept
  13. Congruence modulo n definition
  14. Greatest common divisor definition
  15. Prime number definition
  16. Ring definition
  17. Modular multiplicative inverse definition
  18. Coprime integers definition
  19. Fermat's little theorem statement
  20. Euclid's lemma statement
  21. Existence of a prime divisor statement
  22. Primality test concept
  23. Prime factorization definition
  24. Characteristic of a ring definition
  25. Commutative ring definition
  26. Euler's totient function definition
  27. Miller–Rabin primality test concept
  28. Existence of prime factorization statement
  29. Freshman's dream statement
  30. Euler's theorem statement
  31. Fundamental theorem of arithmetic statement
  32. AKS primality test statement
  33. RSA cryptosystem example
  34. Integer factorization problem
  35. Shor's algorithm statement

Further reading

  1. Web https://en.wikipedia.org/wiki/Shor%27s_algorithm
About this page
Tag83G4EPJ3EJ
URIm2://83G4EPJ3EJ
Kindstatement, theorem
WritingW0 stub
MSC68Q12, 81P68, 11Y05
StatusThis copy of the site has no build data. Run m2 status 83G4EPJ3EJ.
AboutInteger factorization, Quantum complexity class BQP
UsesQuantum complexity class BQP, Integer factorization, Order of an element
Same as
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.