Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
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).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