Fermat's Difference of Squares Factorization
In 1643, Pierre de Fermat discovered that every odd composite number n can be factored by finding two integers x and y such that:
n = x² - y² = (x - y)(x + y) = p × q
The algorithm sets the initial candidate to the ceiling of the square root, x = ⌈√n⌉, and computes the remainder:
r = x² - n
If r is a perfect square, say r = y², we have found the factors p = x - y and q = x + y. If not, x is incremented by 1. Because:
(x + 1)² - n = (x² - n) + (2x + 1)
The remainder can be updated using only additions: r += 2x + 1, completely eliminating expensive multiplications from the inner loop.
The Sieve of Ma'at: Legendre Symbol Quadratic Residue Filter
Testing whether an integer is an exact square using square roots is computationally costly. However, a square y² must be a quadratic residue modulo every prime p.
For any prime p, the Legendre symbol (a/p) indicates whether a is a quadratic residue modulo p:
- (a/p) = 1 → a is a quadratic residue modulo p.
- (a/p) = -1 → a is a quadratic non-residue modulo p (it is impossible for a to be a square).
- (a/p) = 0 → p divides a.
By checking r against precomputed Legendre lookup tables for 20 small primes (3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73), more than 99.999% of non-squares are rejected in a fraction of a microsecond before any square root is attempted!
The RSA Vulnerability: Why Primes Must Not Be Close
In textbook RSA key generation, the modulus is n = p × q. If the primes p and q are chosen too close to each other, Fermat's difference of squares factorization cracks the private key almost instantly!
When |p - q| is small:
x = (p + q) / 2 ≈ √n
The initial candidate x = ⌈√n⌉ is already adjacent to the true factor midpoint. In the Ramses II preset above, a 34-bit RSA modulus (n = 10,969,629,527 = 104,723 × 104,749) is factored in step 1! This visually demonstrates why cryptographic standards (FIPS 186-4, RFC 8017) strictly require |p - q| > 2nlen/2 - 100.
Ancient Egyptian Hieroglyphic Numerals
Ancient Egyptians used a base-10 additive numeral system represented in stone carvings across temples, tombs, and papyri (such as the Rhind and Moscow Mathematical Papyri). Numbers were written by repeating glyphs for each power of 10:
| Value | Glyph | Egyptian Name / Symbol | Description |
|---|---|---|---|
| 1 | πΊ | Single vertical stroke | A single tally mark carved in stone |
| 10 | π | Hobble / Heel bone (medj) | An arch of woven cattle hobble |
| 100 | π’ | Coil of rope (shet) | A coil of measuring surveyor rope |
| 1,000 | πΌ | Lotus plant (khaa) | A water lily blooming in the Nile |
| 10,000 | π | Pointing finger (djeba) | A bent finger pointing upwards |
| 100,000 | π | Tadpole / Frog (hefen) | A fertile tadpole in the Nile mud |
| 1,000,000 | π¨ | God Heh (heh) | The god Heh kneeling with upraised arms supporting eternity |