← LibraryDivisibility, Ideals and Unique FactorizationEngineering · MathematicsLesson 8/32← PrevNext →
ArticlePublished 6 Aug 2026Updated 5 Aug 202610 min readBy Kevin Jogin
KEVOS® Knowledge Library · Engineering → Mathematics

Engineering/Mathematics/Foundations of number theory

Divisibility, Ideals and Unique Factorization

Every modular algorithm, every public-key scheme and every finite-field construction rests on four facts about the integers: you can divide with remainder, ideals are principal, greatest common divisors are linear combinations, and factorization into primes is unique.

  • Foundation layer
  • Number theory
  • Proof-based
  • ≈18 min read
  • Prerequisite for 20+ pages
1Generator per idealEvery ideal of ℤ has the form dℤ for a unique d ≥ 0. This single fact produces the gcd, Bézout's identity and the Chinese remainder theorem.
PrimesEuclid's argument: no finite list of primes can be complete, because the product of the list plus one has a prime factor outside it.
O(ℓ²)Cost of gcdEuclid's algorithm on two ℓ-bit integers, using classical arithmetic — fast, and completely independent of how hard the inputs are to factor.
UniqueFactorizationEvery positive integer is a product of primes in exactly one way up to order. Uniqueness — not existence — is the hard and useful half.

01

Executive summary

Elementary number theory is often taught as a collection of tricks about integers. It is more useful, and far more portable to algorithms, when it is taught as the study of a single algebraic object: the ring and its ideals. Divisibility becomes containment of ideals, the greatest common divisor becomes an ideal generator, and Bézout's identity becomes a statement that a certain ideal is principal.

That reframing is what makes the material transfer. The same argument that gives unique factorization of integers gives unique factorization of polynomials over a field; the same extended Euclidean algorithm that inverts an integer modulo n inverts a polynomial modulo an irreducible, which is how finite fields are built in practice.

01

Structural view

Divisibility, gcd and lcm are properties of the ideals aℤ, not of decimal representations of numbers.

02

Algorithmic view

gcd is cheap; factorization is not. The gap between these two costs is the economic basis of RSA.

03

Transfer view

Every result here has a mirror image in F[X], the polynomials over a field, with degree replacing absolute value.

Contents

02

Definitions and notation

Fix the vocabulary once; it is used unchanged across the whole library.

Definition D1

Divisibility

For a, b ∈ ℤ we write a ∣ b (“a divides b”) when b = ac for some integer c. Then a is a divisor of b and b is a multiple of a. Note that every integer divides 0, and only ±1 divides 1.

Definition D2

Prime and composite

An integer p > 1 is prime if its only positive divisors are 1 and p; otherwise it is composite. The number 1 is a unit and is deliberately neither — treating it as prime would destroy the uniqueness of factorization.

Core relations and their algebraic reading
Arithmetic statementIdeal-theoretic statementWhy it matters
a ∣ bbℤ ⊆ aℤDivisibility is reverse containment: bigger ideal, smaller divisor.
d = gcd(a,b)aℤ + bℤ = dℤThe gcd is the generator of the sum of two ideals.
m = lcm(a,b)aℤ ∩ bℤ = mℤThe lcm is the generator of the intersection.
gcd(a,b) = 1aℤ + bℤ = ℤCoprimality is the statement that 1 is a combination of a and b.
p primepℤ maximalp is a field precisely when p is prime.

This table is the bridge between elementary arithmetic and the ring theory used later in the library.

Contents

03

Division with remainder

Everything computational begins with a statement that looks trivial and is not.

Theorem T1

Division with remainder

For a ∈ ℤ and b > 0 there exist unique q, r ∈ ℤ with a = bq + r and 0 ≤ r < b.Write q = ⌊a/b⌋ and r = a − bq, denoted a mod b.

Existence follows from the well-ordering of the non-negative integers applied to the set {a − bq : q ∈ ℤ, a − bq ≥ 0}; uniqueness follows because two candidate remainders differ by a multiple of b that is smaller than b in absolute value.

Sign conventions matter in code

The mathematical convention above always yields 0 ≤ r < b. Many programming languages implement truncated division instead, so -7 % 3 returns -1 in C, Java, Go and Rust, but 2 in Python. Modular code written against the mathematical convention must normalise remainders explicitly, or it will fail on negative operands in ways that are silent and intermittent.

Division with remainder is what makes a Euclidean domain: there is a size measure (absolute value) that strictly decreases under remaindering. The polynomial ring F[X] over a field has the same property with degree as the size measure, which is exactly why the same algorithms run there.

Contents

04

Ideals and the greatest common divisor

The one structural result that generates all the rest.

An ideal of is a non-empty subset I closed under addition and under multiplication by arbitrary integers. The sets dℤ = {dk : k ∈ ℤ} are ideals; the content of the next theorem is that there are no others.

Theorem T2

ℤ is a principal ideal domain

Every ideal I ⊆ ℤ equals dℤ for a unique d ≥ 0. Proof sketch: if I = {0} take d = 0; otherwise let d be the smallest positive element of I. For any a ∈ I, write a = dq + r with 0 ≤ r < d. Then r = a − dq ∈ I, and minimality of d forces r = 0.

Apply this to I = aℤ + bℤ = {as + bt : s,t ∈ ℤ}, which is visibly an ideal. Its generator is by definition gcd(a,b), and two properties fall out immediately:

  • Bézout's identity. There exist integers s,t with as + bt = gcd(a,b). The extended Euclidean algorithm computes them in the same asymptotic time as the gcd itself.
  • Common divisors divide the gcd. If c ∣ a and c ∣ b then c ∣ as + bt, hence c ∣ gcd(a,b). The gcd is therefore greatest in the divisibility order, not merely in magnitude — a stronger and more usable statement.

The definition you should carry

Define gcd(a,b) as the non-negative generator of aℤ + bℤ, not as “the largest common divisor.” The generator definition handles gcd(0,0) = 0 correctly, extends verbatim to polynomials, and makes Bézout's identity a triviality rather than a theorem.

Contents

05

Primes and the fundamental theorem of arithmetic

Existence of a prime factorization is a short induction: any n > 1 is either prime or splits into two smaller factors. Uniqueness is where the real content lies, and it depends on one lemma.

Theorem T3

Euclid's lemma

If p is prime and p ∣ ab, then p ∣ a or p ∣ b. Proof: if p ∤ a then gcd(p,a) = 1, so ps + at = 1 for some s,t. Multiplying by b gives b = psb + abt, and p divides both terms on the right.

Theorem T4

Fundamental theorem of arithmetic

n = ∏p pνp(n)The exponents ν_p(n) ≥ 0 are uniquely determined; all but finitely many are zero.

Every integer n > 0 factors into primes, and the multiset of prime factors is unique. Uniqueness follows from Euclid's lemma by induction on n.

The valuation calculus

Writing νp(n) for the exponent of p in n converts multiplicative questions into additive ones:

Divisibility identities in exponent form
QuestionExponent formConsequence
a ∣ bνp(a) ≤ νp(b) for all pDivisibility is a componentwise order on exponent vectors.
gcd(a,b)min(νp(a), νp(b))Correct, but computationally useless — it needs the factorizations.
lcm(a,b)max(νp(a), νp(b))Gives gcd(a,b) · lcm(a,b) = |ab| from min + max = sum.
n is a perfect squareall νp(n) evenThe parity of exponent vectors is the entire idea behind the quadratic sieve.
a and b coprime, ab a squaredisjoint supports, all evenStandard step in descent arguments and in Pythagorean parametrisation.
Contents

06

What unique factorization buys you

01

Irrationality proofs

If √n were rational, some prime would carry an odd exponent on one side of an equation and an even exponent on the other. The argument is uniform, not special to √2.

02

Rational root test

A rational root r/t in lowest terms of an integer polynomial has t dividing the leading coefficient and r dividing the constant term.

03

Canonical fractions

Every rational has a unique representation a/b with b > 0 and gcd(a,b) = 1 — the basis of exact rational arithmetic and of rational reconstruction.

04

Multiplicative functions

Any function determined by its values on prime powers is determined everywhere: this is what makes φ, μ and σ tractable.

05

Smoothness

A number is y-smooth when every νp(n) > 0 has p ≤ y. Sieve-based factoring is built entirely on counting smooth numbers.

06

Structure of ℤn

The Chinese remainder theorem decomposes n along the prime-power factorization of n, reducing most modular questions to prime powers.

Theorem T5

Infinitude of primes, with a bound

Suppose p1, …, pk were all the primes. Then N = p1⋯pk + 1 is greater than 1 and is divisible by no pi, contradicting the existence half of unique factorization. The argument also yields a crude bound: the k-th prime is at most 22k. Sharper density results are treated separately.

Contents

07

The computational fault line

Which of these operations are cheap, and which are believed to be hard.

The whole of applied number theory lives in the gap between two problems that sound similar and are not.

Relative difficulty on ℓ-bit inputs (classical algorithms, schematic)
Addition, comparisonO(ℓ)
Multiplication (schoolbook)O(ℓ²)
gcd, extended gcdO(ℓ²)
Modular exponentiationO(ℓ³)
Primality test (Miller–Rabin)O(k·ℓ³)
Factoring (number field sieve)subexponential in ℓ

Do not compute gcds by factoring

The identity gcd(a,b) = ∏ pmin(νp(a),νp(b)) is true and it is a trap. Evaluating it requires factoring both inputs, which is exponentially harder than the Euclidean algorithm that answers the same question directly. Unique factorization is a proof device here, not an algorithm.

The same asymmetry, expressed positively, is the reason RSA can exist: generating two large primes and multiplying them is cheap, while recovering them from the product is not.

Contents

08

Common mistakes

Errors seen repeatedly in implementations and proofs
MistakeWhy it is wrongCorrect practice
Treating 1 as primeUniqueness of factorization fails immediately — you could append any number of 1s.Units are excluded from the prime list by definition.
gcd(0,0) undefined or set to 1The ideal 0ℤ + 0ℤ is {0}, whose generator is 0.Define gcd(0,0) = 0; library code should return 0 and not raise.
Assuming a ∣ bc ⇒ a ∣ b or a ∣ cEuclid's lemma requires a prime; 6 ∣ 4·3 but divides neither.Use gcd(a,b) = 1 ⇒ (a ∣ bc ⇒ a ∣ c) in the general case.
Cancelling freely in congruences2·3 ≡ 2·0 (mod 6) does not give 3 ≡ 0.Cancel only by elements coprime to the modulus.
Language % assumed non-negativeTruncated division returns negative remainders for negative operands.Normalise once at the boundary of the modular layer.
Assuming unique factorization is automaticIt fails in rings such as ℤ[√−5], where 6 has two genuinely different factorizations.Cite the property explicitly when generalising to other rings.
Contents

09

Quick reference

One-line facts
FactStatement
Divisiona = bq + r, 0 ≤ r < b, q,r unique
Bézout∃ s,t : as + bt = gcd(a,b)
Coprime testgcd(a,b) = 1 ⟺ ∃ s,t : as + bt = 1
gcd–lcmgcd(a,b)·lcm(a,b) = |ab|
Euclid's lemmap prime, p ∣ ab ⇒ p ∣ a or p ∣ b
FTAn = ∏ pνp(n), exponents unique
Divisor countτ(n) = ∏ (νp(n) + 1)
Divisor sumσ(n) = ∏ (pνp(n)+1 − 1)/(p − 1)
Trial division boundn composite ⇒ it has a prime factor ≤ √n
Why is uniqueness of factorization harder to prove than existence?
Existence is a finite descent: keep splitting composites. Uniqueness needs Euclid's lemma, which in turn needs Bézout's identity, which needs the fact that every ideal of is principal. There are rings where existence holds and uniqueness fails, which shows the second half is genuinely extra content.
Is the gcd defined for negative numbers?
Yes. gcd(a,b) = gcd(|a|,|b|), because aℤ = (−a)ℤ. Conventionally the gcd is taken non-negative so that the generator of the ideal is unique.
Does any of this change for polynomials?
Almost nothing changes. Replace |·| by degree, replace “non-negative generator” by “monic generator”, and every statement on this page holds in F[X] for a field F. That is why polynomial gcd, polynomial CRT and finite-field construction reuse the integer algorithms unchanged.
How large can the gcd computation get in practice?
The Euclidean algorithm performs O(ℓ) division steps on ℓ-bit inputs, each costing O(ℓ) word operations in the classical model, so O(ℓ²) overall. For 4096-bit inputs this is milliseconds — orders of magnitude cheaper than a single modular exponentiation of the same size.
Contents

11

References and further reading

  • V. Shoup, A Computational Introduction to Number Theory and Algebra, Cambridge University Press, 2005 — Chapter 1 (basic properties of the integers). Author's electronic edition available at shoup.net/ntb.
  • G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, 6th ed., Oxford, 2008 — classical treatment of divisibility and the fundamental theorem.
  • D. E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed., Addison-Wesley, 1997 — §4.5 on gcd computation and its complexity.
  • K. Ireland and M. Rosen, A Classical Introduction to Modern Number Theory, 2nd ed., Springer, 1990 — unique factorization in general rings and where it fails.

KEVOS® Knowledge LibraryEngineering → MathematicsTaxonomy ID: ENG-MATHPage ID: divisibility-ideals-unique-factorizationReview cycle: annual


Continue learning

NEXT LESSON →Congruences and Modular ArithmeticArticle · MathematicsEuler's Phi Function and Fermat's Little TheoremArticle · MathematicsArithmetic Functions and Möbius InversionArticle · MathematicsThe Distribution of PrimesArticle · Mathematics