Skip to content
LUDA · 學思辨行

LUDA · 學思辨行

Learn extensively, Understand deeply, Discern clearly, and Act resolutely.

  • About
  • Learning Path

Category: Number Theory

How Tonelli-Shanks takes a square root mod p

November 13, 2026By HoHo Zhao

Short answer: Tonelli-Shanks computes a square root of a modulo an odd prime p, given that a is a quadratic residue. Write p−1 = q·2^s with q odd. Find a quadratic nonresidue z, set an initial guess from a^{(q+1)/2}, and then walk a 2-power tower that corrects the guess…

Algorithms, Number TheoryLeave a comment

How the sieve of Eratosthenes strikes composites

November 13, 2026By HoHo Zhao

Short answer: The sieve of Eratosthenes lists every prime up to n by striking multiples. For each prime p whose square is still at most n, it marks p·p, p·p+p, p·p+2p, and so on. Multiples below p² were already marked by smaller primes. The algorithm runs in O(n log…

Algorithms, Number TheoryLeave a comment

How the Lucas-Lehmer test checks a Mersenne number

November 13, 2026By HoHo Zhao

Short answer: The Lucas-Lehmer test decides whether a Mersenne number M = 2^p − 1 is prime, for an odd prime p. It sets s = 4 and repeats s = s² − 2, modulo M, p−2 times. M is prime exactly when the final s is 0 modulo…

Algorithms, Number TheoryLeave a comment

How the linear sieve marks each composite once

November 13, 2026By HoHo Zhao

Short answer: The linear sieve computes the smallest prime factor of every integer up to n in O(n) arithmetic steps. It walks i from 2 to n, records i as prime when it has no factor yet, and for each known prime p marks p·i, stopping when p divides…

Algorithms, Number TheoryLeave a comment

How the extended Euclidean algorithm writes Bezout

November 13, 2026By HoHo Zhao

Short answer: The extended Euclidean algorithm returns integers x and y such that a·x + b·y = gcd(a, b). It runs the same divisions as the Euclidean algorithm and also updates two coefficient rows, one for each remainder. The modular inverse of a modulo m exists exactly when the…

Algorithms, Number TheoryLeave a comment

How the Euclidean algorithm divides out a gcd

November 13, 2026By HoHo Zhao

Short answer: The Euclidean algorithm computes gcd(a, b) by replacing the pair with (b, a mod b) until the remainder is 0. The other number is the gcd. It runs in O(log min(a, b)) division steps, and the worst case is a pair of consecutive Fibonacci numbers, which makes…

Algorithms, Number TheoryLeave a comment

How the Chinese remainder theorem builds a residue

November 13, 2026By HoHo Zhao

Short answer: The Chinese remainder theorem says that if the moduli m1, …, mk are pairwise coprime, then for any residues a1, …, ak there is one solution modulo M = m1·…·mk of the system x ≡ ai (mod mi). The constructive form computes, for each i, the product…

Algorithms, Number TheoryLeave a comment

How the AKS test proves primality in polynomial time

November 13, 2026By HoHo Zhao

Short answer: The AKS primality test decides whether an integer n is prime in time polynomial in the number of bits of n. It generalizes the observation that n is prime exactly when (x−1)^n ≡ x^n − 1 (mod n) as a polynomial, and it checks a related congruence…

Algorithms, Number TheoryLeave a comment

How Pollard’s rho hunts a factor on a cycle

November 13, 2026By HoHo Zhao

Short answer: Pollard’s rho looks for a nontrivial factor of a composite n by iterating a polynomial, usually x² + c, modulo n, and taking gcd of n with the difference of two values on the sequence. By the birthday paradox the sequence cycles quickly modulo a secret prime…

Algorithms, Number TheoryLeave a comment

How Miller-Rabin tests a strong pseudoprime

November 13, 2026By HoHo Zhao

Short answer: The Miller-Rabin test writes an odd number n as d·2^s + 1 and looks at a^d mod n. The test passes for a base a when that power is 1, or when some a^{d·2^r} mod n equals n−1 for an r before s. A prime passes for…

Algorithms, Number TheoryLeave a comment

How binary exponentiation squares a power

November 13, 2026By HoHo Zhao

Short answer: Binary exponentiation computes a^e with O(log e) multiplications by scanning the bits of the exponent. The square-and-multiply loop squares a running power for every bit and multiplies by the base when the bit is 1. The same loop with every multiplication reduced modulo m computes a^e mod…

Algorithms, Number TheoryLeave a comment

How baby-step giant-step solves a discrete log

November 13, 2026By HoHo Zhao

Short answer: Baby-step giant-step solves g^x ≡ h (mod p) for a small x by writing x = i·m − j with m = ceil(sqrt(N)) and x in a range of length N. It stores the baby steps g^j for j = 0..m−1 in a hash table, then walks…

Algorithms, Number TheoryLeave a comment
  • Algorithms
  • Arithmetic
  • Authelia
  • Clustering
  • Coding
  • Compression
  • Cryptography
  • CSS
  • Distributed Systems
  • Docker
  • Dynamic Programming
  • Exact Algorithms
  • Games
  • Geometry
  • Grafana
  • Graphs
  • Greedy
  • Heaps
  • Homelab
  • IPsec
  • LDAP
  • Linear Algebra
  • Logging
  • Loki
  • nginx
  • Number Theory
  • Numerical
  • Optimization
  • Parsing
  • Prometheus
  • Randomization
  • Range Queries
  • Sampling
  • Scheduling
  • Search
  • Searching
  • Sequences
  • Sketches
  • Sorting
  • Streams
  • Strings
  • SVG
  • Synchronization
  • Systems
  • Transforms
  • Trees

Docker EAP-MSCHAPv2 FreeRADIUS Grafana gzip IKEv2 IPsec LogQL Loki OpenLDAP Promtail StrongSwan

© 2026 LUDA · 學思辨行. Powered by WordPress.