Number Theory Basics Cheat Sheet

Number theory fundamentals — prime numbers, GCD/LCM, modular arithmetic, Euler's theorem, RSA basics, and primality testing for cryptography.

Last Updated: July 15, 2025

Fundamentals

ConceptDefinitionExample
PrimeInteger > 1 divisible only by 1 and itself2, 3, 5, 7, 11, 13, 17, 19, 23
GCD(a,b)Greatest common divisorGCD(48, 18) = 6
LCM(a,b)Least common multipleLCM(12, 18) = 36
CoprimeGCD(a,b) = 18 and 15 are coprime
φ(n)Euler's totient — numbers ≤ n coprime to nφ(10) = 4 ({1,3,7,9})

Modular Arithmetic

PropertyFormula
Addition(a + b) mod m = ((a mod m) + (b mod m)) mod m
Multiplication(a × b) mod m = ((a mod m) × (b mod m)) mod m
Modular Inversea⁻¹ mod m exists iff GCD(a,m) = 1
Fermat's LittleIf p prime, a⊥p: a^(p−1) ≡ 1 (mod p)
Euler's TheoremIf GCD(a,n)=1: a^φ(n) ≡ 1 (mod n)

RSA Key Generation

1. Pick primes p, q
Large random primes (2048-bit total)
2. Compute n = p × q
Modulus — public and private key share n
3. Compute φ(n) = (p−1)(q−1)
Euler's totient of n
4. Choose e
Public exponent — 1 < e < φ(n), GCD(e, φ(n)) = 1 (commonly 65537)
5. Compute d = e⁻¹ mod φ(n)
Private exponent — extended Euclidean algorithm

Primality Testing

TestTypeSpeed
Trial DivisionDeterministic — divide by all primes ≤ √nO(√n) — slow for large n
Fermat TestProbabilistic — check a^(n−1) ≡ 1 mod nFast — Carmichael numbers false
Miller-RabinProbabilistic — k rounds, error ≤ 4⁻ᵏIndustry standard — k=40 for crypto
AKSDeterministic — polynomial timeTheoretical — too slow in practice
Pro Tip: Public-key cryptography rests on the hardness of factoring large primes. RSA-2048 would take a classical computer billions of years to break — but Shor's algorithm on a quantum computer changes everything.
Part of the Empire Builder Network