Olympiad Number Theory V: Legendre, Pell & Möbius

Study Sheet

Olympiad Number Theory V: Legendre, Pell & Möbius

Valuations in factorials, the Legendre symbol, Pell equations, multiplicative functions and Möbius inversion, Bertrand

Valuations, residues and reciprocity

Tip
Legendre's formula

vp(n!)=∑k≥1⌊npk⌋=n−sp(n)p−1v_p(n!) = \sum_{k\ge1}\left\lfloor\dfrac{n}{p^k}\right\rfloor = \dfrac{n - s_p(n)}{p-1}, where sp(n)s_p(n) is the digit sum of nn in base pp.

It answers every "how many trailing zeros / what power of pp divides" question in one line: v3(1000!)=333+111+37+12+4+1=498v_3(1000!) = 333 + 111 + 37 + 12 + 4 + 1 = 498, and the digit-sum form confirms it since 1000=(1101001)31000 = (1101001)_3 has digit sum 44 and 1000−42=498\tfrac{1000-4}{2} = 498. Combined with Kummer's theorem — vp(m+nn)v_p\binom{m+n}{n} is the number of carries when adding mm and nn in base pp — it also controls binomial coefficients, which is where the olympiad applications live.

Tip
The Legendre symbol and reciprocity

(ap)\left(\tfrac{a}{p}\right) is +1+1 if aa is a nonzero square mod pp, −1-1 otherwise. Euler: (ap)≡a(p−1)/2\left(\tfrac{a}{p}\right)\equiv a^{(p-1)/2}. It is multiplicative in aa. Reciprocity: (pq)(qp)=(−1)p−12q−12\left(\tfrac{p}{q}\right)\left(\tfrac{q}{p}\right) = (-1)^{\frac{p-1}{2}\frac{q-1}{2}}, with (−1p)=(−1)(p−1)/2\left(\tfrac{-1}{p}\right) = (-1)^{(p-1)/2} and (2p)=(−1)(p2−1)/8\left(\tfrac{2}{p}\right) = (-1)^{(p^2-1)/8}.

Multiplicativity is what makes it fast: to test 11 through 3030 modulo 101101 you evaluate eight prime symbols and multiply, finding 1717 residues — 1,4,5,6,9,13,14,16,17,19,20,21,22,23,24,25,301, 4, 5, 6, 9, 13, 14, 16, 17, 19, 20, 21, 22, 23, 24, 25, 30. Exactly half of the 100100 nonzero classes are squares, so a count near 1515 is the sanity check. The symbol is also the standard way to prove a Diophantine equation has no solutions: reduce mod a well-chosen prime and show one side is a non-residue.

Tip
Pell equations

x2−dy2=1x^2 - dy^2 = 1 with dd a positive non-square has infinitely many solutions; the fundamental one comes from the continued fraction of d\sqrt d, and all others are (x1+y1d)n(x_1 + y_1\sqrt d)^n.

The solutions grow fast, so searching is hopeless: for d=13d = 13 the smallest is (649,180)(649, 180), which no hand search finds. The continued fraction 13=[3;1,1,1,1,6‾]\sqrt{13} = [3;\overline{1,1,1,1,6}] has odd period, so the first convergent of the period, 185\tfrac{18}{5}, solves x2−13y2=−1x^2 - 13y^2 = -1 and its square (18+513)2=649+18013(18+5\sqrt{13})^2 = 649 + 180\sqrt{13} solves +1+1. In olympiad use, Pell supplies the infinite family in "show there are infinitely many nn such that ..." and the recursion xn+1=2x1xn−xn−1x_{n+1} = 2x_1x_n - x_{n-1} supplies the induction.

Side note
Lifting the exponent, one line

For odd pp with p∣a−bp \mid a - b and p∤a,bp \nmid a, b: vp(an−bn)=vp(a−b)+vp(n)v_p(a^n - b^n) = v_p(a-b) + v_p(n). The p=2p = 2 case needs v2(an−bn)=v2(a−b)+v2(a+b)+v2(n)−1v_2(a^n - b^n) = v_2(a-b) + v_2(a+b) + v_2(n) - 1 for even nn. LTE plus Legendre's formula settles most "largest power of pp dividing" problems outright.

Example
Worked: reciprocity by hand

Is 219219 a quadratic residue modulo the prime 383383?

Step 1 — factor the top: 219=3⋅73219=3\cdot73, so (219383)=(3383)(73383)\left(\tfrac{219}{383}\right)=\left(\tfrac3{383}\right)\left(\tfrac{73}{383}\right).

Step 2 — 33 and 383383 are both ≡3(mod4)\equiv3\pmod4, so reciprocity flips the sign: (3383)=−(3833)=−(23)=−(−1)=1\left(\tfrac3{383}\right)=-\left(\tfrac{383}3\right)=-\left(\tfrac23\right)=-(-1)=1.

Step 3 — 73≡1(mod4)73\equiv1\pmod4, so no sign: (73383)=(38373)=(1873)=(273)(973)=(273)=1\left(\tfrac{73}{383}\right)=\left(\tfrac{383}{73}\right)=\left(\tfrac{18}{73}\right)=\left(\tfrac2{73}\right)\left(\tfrac9{73}\right)=\left(\tfrac2{73}\right)=1, since 73≡1(mod8)73\equiv1\pmod8.

Step 4 — so (219383)=1\left(\tfrac{219}{383}\right)=1: 219219 is a square mod 383383. (Euler's criterion confirms it: 219191≡1(mod383)219^{191}\equiv1\pmod{383}.)

How to find it. Factor the top into primes, flip each prime symbol with reciprocity, reduce the new top modulo the new bottom, and repeat — a Euclid-like descent in which only the supplements for −1-1 and 22 are ever evaluated directly.

Example
Worked: (2nn)\binom{2n}{n} divides lcm⁡(1,…,2n)\operatorname{lcm}(1,\dots,2n)

Prove that (2nn)\dbinom{2n}{n} divides lcm⁡(1,2,…,2n)\operatorname{lcm}(1,2,\dots,2n) for every n≥1n\ge1. (folklore; used in Chebyshev-type prime estimates)

Step 1 — compare exponents prime by prime. For a prime pp, vp(lcm⁡(1,…,2n))v_p\left(\operatorname{lcm}(1,\dots,2n)\right) is the largest kk with pk≤2np^k\le2n, namely ⌊log⁡p2n⌋\lfloor\log_p2n\rfloor.

Step 2 — by Kummer, vp(2nn)v_p\binom{2n}n is the number of carries when n+nn+n is added in base pp.

Step 3 — a carry out of position ii produces a nonzero digit (or a new leading digit) in position i+1i+1 of 2n2n, so every carry happens at a position ii with pi+1≤2np^{i+1}\le2n. There are at most ⌊log⁡p2n⌋\lfloor\log_p2n\rfloor such positions.

Step 4 — so vp(2nn)≤vp(lcm⁡)v_p\binom{2n}n\le v_p(\operatorname{lcm}) for every pp, which is the claim. Example: (105)=252=22⋅32⋅7\binom{10}5=252=2^2\cdot3^2\cdot7 divides lcm⁡(1,…,10)=2520\operatorname{lcm}(1,\dots,10)=2520.

How to find it. Divisibility between two integers is a prime-by-prime comparison of valuations. Kummer turns the binomial's valuation into a digit count, and the lcm's valuation is also a digit count — the number of base-pp digits of 2n2n, minus one.

Side note
Where it goes wrong: a symbol modulo a composite

Tempting: "compute (215)=(23)(25)=(−1)(−1)=1\left(\tfrac2{15}\right)=\left(\tfrac23\right)\left(\tfrac25\right)=(-1)(-1)=1, so 22 is a square mod 1515." But the squares mod 1515 are 0,1,4,6,9,100,1,4,6,9,10, and 22 is not among them.

The product (23)(25)\left(\tfrac23\right)\left(\tfrac25\right) is the Jacobi symbol, which obeys reciprocity but does not detect squares: 22 is a non-residue both mod 33 and mod 55, and two failures multiply to +1+1. By the Chinese remainder theorem, aa is a square mod 1515 exactly when it is a square mod 33 and mod 55. The Jacobi symbol is safe for one thing: a value of −1-1 proves non-residuosity. A value of +1+1 proves nothing modulo a composite.

Try it
Try it: v2(10050)v_2\binom{100}{50}

Find the exponent of 22 in (10050)\dbinom{100}{50} in two ways: with Legendre's formula, and by counting carries.

Show the answer

Legendre: v2(100!)=50+25+12+6+3+1=97v_2(100!)=50+25+12+6+3+1=97 and v2(50!)=25+12+6+3+1=47v_2(50!)=25+12+6+3+1=47, so v2(10050)=97−2⋅47=3v_2\binom{100}{50}=97-2\cdot47=3. Kummer: 50=110010250=110010_2, and adding 110010+110010110010+110010 carries out of each position holding a 11 — three positions — so again 33. In general v2(2nn)v_2\binom{2n}n is the number of 11s in the binary expansion of nn.

Multiplicative functions and Möbius

Tip
The standard multiplicative functions

τ(n)\tau(n) (number of divisors), σ(n)\sigma(n) (their sum), φ(n)\varphi(n) (Euler totient) and μ(n)\mu(n) (Möbius: 00 if nn has a square factor, else (−1)#primes(-1)^{\#\text{primes}}) are all multiplicative: f(mn)=f(m)f(n)f(mn) = f(m)f(n) for coprime m,nm, n.

Multiplicativity reduces every evaluation to prime powers: τ(pk)=k+1\tau(p^k) = k+1, σ(pk)=pk+1−1p−1\sigma(p^k) = \tfrac{p^{k+1}-1}{p-1}, φ(pk)=pk−pk−1\varphi(p^k) = p^k - p^{k-1}, μ(p)=−1\mu(p) = -1, μ(pk)=0\mu(p^k) = 0 for k≥2k\ge2. It also lets you evaluate divisor sums by factoring: ∑d∣60μ(d)d=(1−2)(1−3)(1−5)=−8\sum_{d\mid 60}\mu(d)d = (1-2)(1-3)(1-5) = -8, no enumeration required.

Tip
Möbius inversion
1μ = 12μ = −14μ = 03μ = −16μ = 112μ = 0divisors of 12: ×2 to the right, ×3 upward
Only the squarefree corner 1, 2, 3, 6 carries weight: 1 − 1 − 1 + 1 = 0.

∑d∣nμ(d)=[ n=1 ]\sum_{d\mid n}\mu(d) = [\,n = 1\,]. Hence if g(n)=∑d∣nf(d)g(n) = \sum_{d\mid n} f(d) for all nn, then f(n)=∑d∣nμ(d) g(n/d)f(n) = \sum_{d\mid n}\mu(d)\,g(n/d).

The inversion is how you undo a divisor sum, and the identity ∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d) = n inverts to φ(n)=∑d∣nμ(d)nd\varphi(n) = \sum_{d\mid n}\mu(d)\tfrac nd — equivalently φ(n)n=∏p∣n(1−1p)\tfrac{\varphi(n)}{n} = \prod_{p\mid n}\left(1 - \tfrac1p\right), which is the inclusion–exclusion you would have written by hand. Counting necklaces, primitive roots of unity, and aperiodic strings all reduce to a Möbius sum.

Example
Worked: counting aperiodic necklaces

How many binary strings of length 1212 are primitive (not a repetition of a shorter block)? How many necklaces (strings up to rotation) do they form? (folklore)

Step 1 — every string of length 1212 is a repetition of a unique primitive block of some length d∣12d\mid12. With P(d)P(d) the number of primitive strings of length dd, this says 212=∑d∣12P(d)2^{12}=\sum_{d\mid12}P(d), and the same holds for every length: 2n=∑d∣nP(d)2^n=\sum_{d\mid n}P(d).

Step 2 — Möbius inversion: P(n)=∑d∣nμ(d) 2n/dP(n)=\sum_{d\mid n}\mu(d)\,2^{n/d}. For n=12n=12 only d=1,2,3,6d=1,2,3,6 contribute, with μ=1,−1,−1,1\mu=1,-1,-1,1: P(12)=212−26−24+22=4096−64−16+4=4020P(12)=2^{12}-2^6-2^4+2^2=4096-64-16+4=4020.

Step 3 — a primitive string has 1212 distinct rotations, all primitive, so the 40204020 strings fall into 402012=335\tfrac{4020}{12}=335 necklaces.

How to find it. "Count the objects of exact size nn" when you can easily count "objects of size dividing nn" is always Möbius inversion. The divisibility of 40204020 by 1212 is a free sanity check.

Side note
Where it goes wrong: multiplicative is not completely multiplicative

Tempting: "τ\tau is multiplicative, so τ(4)=τ(2)2=4\tau(4)=\tau(2)^2=4." But 44 has three divisors, 1,2,41,2,4.

Multiplicativity, f(mn)=f(m)f(n)f(mn)=f(m)f(n), is only promised for coprime m,nm,n, and 2,22,2 are not coprime. The values on prime powers are independent data: τ(pk)=k+1\tau(p^k)=k+1, σ(pk)=1+p+⋯+pk\sigma(p^k)=1+p+\cdots+p^k, φ(pk)=pk−pk−1\varphi(p^k)=p^k-p^{k-1}, μ(pk)=0\mu(p^k)=0 for k≥2k\ge2. Factor nn completely into prime powers first, evaluate on each, then multiply. (Functions like nsn^s with f(mn)=f(m)f(n)f(mn)=f(m)f(n) for all m,nm,n are called completely multiplicative; τ,σ,φ,μ\tau,\sigma,\varphi,\mu are not.)

Tip
Bertrand's postulate

For every n≥1n \ge 1 the interval (n,2n](n, 2n] contains a prime; for n>3n > 3 there is one strictly between nn and 2n−22n - 2.

Bertrand is a citation, not a computation: it instantly gives "there is a prime pp with n2<p≤n\tfrac n2 < p \le n", which kills problems asking you to find a prime in a range or to show some product is not a perfect power. Small intervals are tight — (5,10](5,10] holds only the prime 77, and that is the last time a Bertrand interval holds just one — so a proof that leans on two primes in (n,2n](n,2n] must start at n=6n = 6.

Try it
Try it: a Möbius evaluation

Compute ∑d∣30μ(d)\sum_{d\mid 30}\mu(d).

Show the answer

Zero. 30>130 > 1, so the identity ∑d∣nμ(d)=[ n=1 ]\sum_{d\mid n}\mu(d) = [\,n=1\,] gives 00 — check: 1−1−1−1+1+1+1−1=01 - 1 - 1 - 1 + 1 + 1 + 1 - 1 = 0 over 1,2,3,5,6,10,15,301,2,3,5,6,10,15,30.

Proofs & Why It Matters

Tip
Proof: Legendre's formula

vp(n!)=∑k≥1⌊n/pk⌋v_p(n!) = \sum_{k\ge1}\left\lfloor n/p^k\right\rfloor.

Count the factor pp in 1,2,…,n1, 2, \dots, n by layers: ⌊n/p⌋\left\lfloor n/p\right\rfloor of the numbers are divisible by pp, and of those ⌊n/p2⌋\left\lfloor n/p^2\right\rfloor are divisible again, and so on. Each multiple of pkp^k is counted once in each of the first kk layers, so it contributes exactly kk — which is its valuation. ■\blacksquare Writing nn in base pp and summing the geometric series turns the sum into n−sp(n)p−1\tfrac{n - s_p(n)}{p-1}, the form that makes digit-sum problems immediate.

Tip
Proof: ∑d∣nμ(d)=[ n=1 ]\sum_{d\mid n}\mu(d) = [\,n = 1\,]

The Möbius function sums to zero over the divisors of any n>1n > 1.

Only squarefree divisors contribute, so if nn has exactly k≥1k \ge 1 distinct prime factors the sum is ∑j=0k(kj)(−1)j=(1−1)k=0\sum_{j=0}^{k}\binom{k}{j}(-1)^j = (1-1)^k = 0; for n=1n = 1 the only divisor is 11 and the sum is 11. ■\blacksquare Everything else about Möbius — the inversion formula, the totient product, inclusion–exclusion over prime divisors — is this identity applied inside a double sum.