Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
The fundamental theorem of arithmetic is the statement that every integer has a unique prime factorisation, up to ordering. 'Unique' is the load-bearing word: it's why divisibility, gcd, and lcm have clean prime-power formulas, why RSA encryption is reversible (because has a known structure when ), and why number-theoretic identities translate into clean computational rules. The theorem looks obvious — of course , what else could it be? — but the uniqueness is genuinely a theorem, and number systems where it fails (like , where ) drove the development of ideal theory. Knowing where the theorem holds and where it doesn't is the difference between number-theoretic intuition and number-theoretic competence.
The fundamental theorem of arithmetic: every integer can be written as a product of primes , and this factorisation is unique up to the order of the factors. Existence comes from strong induction (any composite splits into two smaller factors, recurse). Uniqueness depends on Euclid's lemma: if is prime and , then or — which itself follows from Bézout's identity.
factorint(720).Use these three in order. Each builds on the one before.
In one paragraph, state the fundamental theorem of arithmetic and explain *why* it's surprising — what would the world look like if integers had two genuinely different prime factorisations?
Walk me through both halves of the proof. Existence: strong induction on $n$. Uniqueness: assume two factorisations $p_1 \cdots p_k = q_1 \cdots q_m$ and use Euclid's lemma to peel off one prime at a time. Where does Bézout's identity enter via Euclid's lemma?
Unique factorisation fails in $\mathbb{Z}[\sqrt{-5}]$. Sketch what goes wrong, and explain how Dedekind's introduction of *ideals* restored a unique-factorisation property at the price of factoring ideals instead of elements. Why does this matter for cryptography over algebraic number fields?
math.gcdmath.lcmfactorint will still handle this in milliseconds — but the same call on a 200-digit RSA modulus would take longer than the universe has existed. Try a 30-digit semiprime to see the cost climb.// main.go — run: go run main.go
package main
import (
"fmt"
"sort"
)
// factorint returns the prime factorisation of n as a map prime -> exponent.
func factorint(n int) map[int]int {
factors := map[int]int{}
for d := 2; d*d <= n; d++ {
for n%d == 0 {
factors[d]++
n /= d
}
}
if n > 1 {
factors[n]++
}
return factors
}
// primefactors returns the distinct primes of n in sorted order.
func primefactors(n int) []int {
f := factorint(n)
primes := make([]int, 0, len(f))
for p := range f {
primes = append(primes, p)
}
sort.Ints(primes)
return primes
}
// reconstruct multiplies p^e for each entry — verifies round-trip.
func reconstruct(f map[int]int) int {
n := 1
for p, e := range f {
for i := 0; i < e; i++ {
n *= p
}
}
return n
}
// gcdViaFactor: take the min exponent of each prime shared by both numbers.
func gcdViaFactor(a, b int) int {
fa, fb := factorint(a), factorint(b)
result := 1
for p, ea := range fa {
if eb, ok := fb[p]; ok {
e := ea
if eb < e {
e = eb
}
for i := 0; i < e; i++ {
result *= p
}
}
}
return result
}
func main() {
fmt.Println(factorint(360)) // map[2:3 3:2 5:1] -> 360 = 2^3 * 3^2 * 5
fmt.Println(factorint(1071)) // map[3:2 7:1 17:1]
fmt.Println(primefactors(360)) // [2 3 5] — the distinct primes
// Reconstruct n from its factorisation
fact := factorint(360)
fmt.Println(reconstruct(fact)) // 360
// gcd via prime factorisation
fmt.Println(gcdViaFactor(360, 1071)) // 3
}go run main.go