Factoring algorithm


A factoring algorithm is an algorithm that finds the prime factorization of an integer.

There is currently no known efficient factoring algorithm. Every factoring algorithm so far has a time complexity that is higher order than \(O(n^k)\), polynomial time. The most widely used public-key encryption algorithm, the RSA algorithm, is completely dependent on the computational difficulty of finding the prime factorization of a large composite integer.

With that said, let's look at some inefficient factoring algorithms!

Contents

Trial division


By extending the trial division implementation of a primality test, you can generate the prime factorization of an integer as a sequence of prime factors:

algorithm factorize is
input: one integer, n > 1
output: its prime factorization, as a sequence of integers

prime_factors ← []
for f = 2 to (n - 1)
while n mod f = 0
append f to prime_factors
n ← n div f
if n > 1
append n to prime_factors
return prime_factors

A sequence is different from a set in that it allows duplicate elements. This means the multiplicities of each prime factor will be represented correctly in prime_factors when the algorithm is done running. With optimizations similar to what was done with primality tests, this algorithm can become twice as efficient:

algorithm factorize is
input: one integer, n > 1
output: its prime factorization, as a sequence of integers

prime_factors ← []
while n mod 2 = 0
append 2 to prime_factors
n ← n div 2
f ← 3
while f ≤ floor(√n) (floor function ensures √n is an integer)
if n mod f = 0
append f to prime_factors
n ← n div f
else
f ← f + 2
if n > 1
append n to prime_factors
return prime_factors

Even after optimization, the algorithm is still not efficient enough to find the prime factorization of a large composite integer in a reasonable amount of time... on a classical computer. With quantum computers, which are exponentially faster, this algorithm could hypothetically break RSA encryption.

Logic & Proofs
IntegerRational numberInequalityReal numberTheoremProofStatementProof by exhaustionUniversal generalizationCounterexampleExistence proofExistential instantiationAxiomLogicTruthPropositionCompound propositionLogical operationLogical equivalenceTautologyContradictionLogic lawPredicateDomainQuantifierArgumentRule of inferenceLogical proofDirect proofProof by contrapositiveIrrational numberProof by contradictionProof by casesSummationDisjunctive normal form
Set Theory
SetElementEmpty setUniversal setSubsetPower setCartesian productStringBinary stringEmpty stringSet operationSet identitySet proof
Functions
FunctionFloor functionCeiling functionInverse function
Algorithms
AlgorithmPseudocodeCommandAsymptotic notationTime complexityAtomic operationBrute-force algorithm
Relations
RelationReflexive relationSymmetric relationTransitive relationRelation compositionEquivalence relationEquivalence class
Number Theory
Integer divisionLinear combinationDivision algorithmModular arithmeticPrime factorizationGreatest common divisorLeast common multiplePrimality testFactoring algorithmEuclid's theoremPrime number theoremEuclidean algorithm
Induction
Proof by inductionFibonacci sequenceProof by strong inductionWell-ordering principleSequenceFactorialRecursive definition
Combinatorics
Rule of productRule of sumBijection rulePermutationCombinationComplement ruleExperimentOutcomeSample spaceEventProbabilityProbability distributionUniform distributionMultisetSixfold wayInclusion-exclusion principlePigeonhole principle
Graph Theory
GraphWalkSubgraphRegular graphComplete graphEmpty graphCycle graphHypercube graphBipartite graphComponentEulerian circuitEulerian trailHamiltonian cycleHamiltonian pathTreeHuffman treeSubstringForestPath graphStarSpanning treeWeighted graphMinimum spanning treeGreedy algorithmPrim's algorithm
Recursion
RecursionRecursive algorithmCorrectness proofDivide-and-conquer algorithmSorting algorithmMerge sort