Math Core

Module 3.7 · Number Theory

p-adic valuations and lifting the exponent

Many AIME questions ask "what is the largest power of pp dividing this number?" The number might be 1000!1000!, a binomial coefficient like (20261013)\binom{2026}{1013}, or a difference of powers like 72048−17^{2048} - 1. Three tools answer almost all of them: Legendre's formula for factorials, Kummer's theorem for binomial coefficients, and the lifting-the-exponent lemma (LTE) for an±bna^n \pm b^n.

Valuations

Definition

p-adic valuation

For a prime pp and a nonzero integer nn, vp(n)v_p(n) is the exponent of pp in the prime factorization of nn: the largest kk with pk∣np^k \mid n.

For example, v2(48)=4v_2(48) = 4 and v3(48)=1v_3(48) = 1. Valuations turn multiplication into addition: vp(ab)=vp(a)+vp(b)v_p(ab) = v_p(a) + v_p(b). For sums there is only an inequality, vp(a+b)≥min⁡(vp(a),vp(b))v_p(a + b) \ge \min(v_p(a), v_p(b)), with equality when vp(a)≠vp(b)v_p(a) \ne v_p(b).

Legendre's formula

Legendre's formula

vp(n!)=⌊np⌋+⌊np2⌋+⌊np3⌋+⋯=n−sp(n)p−1,v_p(n!) = \left\lfloor \frac{n}{p} \right\rfloor + \left\lfloor \frac{n}{p^2} \right\rfloor + \left\lfloor \frac{n}{p^3} \right\rfloor + \cdots = \frac{n - s_p(n)}{p - 1},

where sp(n)s_p(n) is the sum of the base-pp digits of nn.

Why the first form. vp(n!)=∑k=1nvp(k)v_p(n!) = \sum_{k=1}^{n} v_p(k). A number kk with vp(k)=jv_p(k) = j should be counted jj times. It is: once among the multiples of pp, once among the multiples of p2p^2, and so on up to pjp^j. There are ⌊n/pi⌋\lfloor n / p^i \rfloor multiples of pip^i up to nn.

Why the second form. Write n=∑dipin = \sum d_i p^i. Then ⌊n/pi⌋=di+di+1p+⋯\lfloor n / p^i \rfloor = d_i + d_{i+1}p + \cdots. Summing over i≥1i \ge 1, digit djd_j contributes dj(1+p+⋯+pj−1)=djpj−1p−1d_j(1 + p + \cdots + p^{j-1}) = d_j \dfrac{p^j - 1}{p - 1}. Adding up gives n−sp(n)p−1\dfrac{n - s_p(n)}{p-1}.

The case p=2p = 2 is especially clean: v2(n!)=n−s2(n)v_2(n!) = n - s_2(n), where s2(n)s_2(n) is the number of 11s in binary.

Kummer's theorem

Kummer's theorem

vp ⁣((m+nm))v_p\!\left(\dbinom{m + n}{m}\right) equals the number of carries when you add mm and nn in base pp.

Why. By the digit form of Legendre,

vp(m+nm)=sp(m)+sp(n)−sp(m+n)p−1.v_p\binom{m+n}{m} = \frac{s_p(m) + s_p(n) - s_p(m+n)}{p - 1}.

Each carry reduces the digit sum by p−1p - 1 (a pp in one column becomes a 11 in the next), so sp(m)+sp(n)−sp(m+n)=(p−1)⋅(carries)s_p(m) + s_p(n) - s_p(m+n) = (p-1) \cdot (\text{carries}).

A consequence: (nk)\binom{n}{k} is not divisible by pp for exactly ∏(di+1)\prod (d_i + 1) values of kk, where did_i are the base-pp digits of nn (those kk whose digits are each at most nn's, so there are no carries). This is Lucas's theorem. For p=2p = 2, the number of odd entries in row nn of Pascal's triangle is 2s2(n)2^{s_2(n)}. Also v2(2nn)=s2(n)v_2\binom{2n}{n} = s_2(n): adding n+nn + n in binary carries once for every 11.

Lifting the exponent

Lifting the exponent (LTE)

Let pp be an odd prime with p∣a−bp \mid a - b and p∤a,bp \nmid a, b. Then for every n≥1n \ge 1,

vp(an−bn)=vp(a−b)+vp(n).v_p(a^n - b^n) = v_p(a - b) + v_p(n).

If also nn is odd, then vp(an+bn)=vp(a+b)+vp(n)v_p(a^n + b^n) = v_p(a + b) + v_p(n) (when p∣a+bp \mid a + b).

For p=2p = 2, with a,ba, b odd and nn even:

v2(an−bn)=v2(a−b)+v2(a+b)+v2(n)−1.v_2(a^n - b^n) = v_2(a - b) + v_2(a + b) + v_2(n) - 1.

For nn odd, simply v2(an−bn)=v2(a−b)v_2(a^n - b^n) = v_2(a - b).

Proof for odd pp. Two steps.

Step 1: if p∤np \nmid n, vp(an−bn)=vp(a−b)v_p(a^n - b^n) = v_p(a - b). Factor an−bn=(a−b)(an−1+an−2b+⋯+bn−1)a^n - b^n = (a - b)(a^{n-1} + a^{n-2}b + \cdots + b^{n-1}). Since a≡b(modp)a \equiv b \pmod p, the second factor is ≡nan−1≢0(modp)\equiv n a^{n-1} \not\equiv 0 \pmod p.

Step 2: vp(ap−bp)=vp(a−b)+1v_p(a^p - b^p) = v_p(a - b) + 1. The second factor is S=∑i=0p−1ap−1−ibiS = \sum_{i=0}^{p-1} a^{p-1-i} b^i. Write b=a+tb = a + t with p∣tp \mid t. Then ap−1−ibi≡ap−1+iap−2t(modp2)a^{p-1-i}b^i \equiv a^{p-1} + i a^{p-2} t \pmod{p^2}, so

S≡pap−1+ap−2t⋅p(p−1)2(modp2).S \equiv p a^{p-1} + a^{p-2} t \cdot \frac{p(p-1)}{2} \pmod{p^2}.

The second term is divisible by p2p^2 (since p∣tp \mid t and pp is odd, so p−12\frac{p-1}{2} is an integer), and the first is divisible by pp exactly once. So vp(S)=1v_p(S) = 1.

Now write n=pkmn = p^k m with p∤mp \nmid m and apply Step 2 kk times and Step 1 once. The ++ version follows by replacing bb with −b-b.

The p=2p = 2 case. For even n=2kmn = 2^k m with mm odd, factor a2k−b2k=(a−b)(a+b)(a2+b2)(a4+b4)⋯(a2k−1+b2k−1)a^{2^k} - b^{2^k} = (a - b)(a + b)(a^2 + b^2)(a^4 + b^4)\cdots(a^{2^{k-1}} + b^{2^{k-1}}). Each a2j+b2ja^{2^j} + b^{2^j} with j≥1j \ge 1 is ≡2(mod4)\equiv 2 \pmod 4, contributing exactly one 22. That gives v2(a−b)+v2(a+b)+(k−1)v_2(a-b) + v_2(a+b) + (k - 1). The odd part mm doesn't change the valuation (Step 1 again).

Common mistake

LTE needs p∣a−bp \mid a - b (or p∣a+bp \mid a + b for the plus version) and p∤abp \nmid ab. For p=2p = 2, the formula with v2(a+b)v_2(a + b) only holds for even nn. Check these conditions before applying it: v3(2n−1)v_3(2^n - 1) isn't v3(1)+v3(n)v_3(1) + v_3(n), because 3∤2−13 \nmid 2 - 1.

Worked example: Legendre two ways

Find v2(100!)v_2(100!).

Floors: 50+25+12+6+3+1=9750 + 25 + 12 + 6 + 3 + 1 = 97. Digits: 100=11001002100 = 1100100_2 has three 11s, so v2(100!)=100−3=97v_2(100!) = 100 - 3 = 97.

Worked example: Kummer

Find v3 ⁣((10050))v_3\!\left(\dbinom{100}{50}\right).

50=1212350 = 1212_3 (since 27+2⋅9+3+2=5027 + 2 \cdot 9 + 3 + 2 = 50). Add 12123+121231212_3 + 1212_3: units 2+2=4=1⋅3+12 + 2 = 4 = 1 \cdot 3 + 1, carry; threes 1+1+1=31 + 1 + 1 = 3, carry; nines 2+2+1=52 + 2 + 1 = 5, carry; twenty-sevens 1+1+1=31 + 1 + 1 = 3, carry. Four carries, so v3=4v_3 = 4 (the sum is 102013=10010201_3 = 100).

Worked example: LTE, odd prime

Find the largest kk such that 3k∣481−13^k \mid 4^{81} - 1.

3∣4−13 \mid 4 - 1 and 3∤43 \nmid 4, so v3(481−1)=v3(3)+v3(81)=1+4=5v_3(4^{81} - 1) = v_3(3) + v_3(81) = 1 + 4 = 5.

Worked example: LTE, p = 2

Find v2(764−1)v_2(7^{64} - 1).

6464 is even: v2(7−1)+v2(7+1)+v2(64)−1=1+3+6−1=9v_2(7 - 1) + v_2(7 + 1) + v_2(64) - 1 = 1 + 3 + 6 - 1 = 9.

Practice

Practice 1

Find the largest integer kk such that 3k3^k divides 1000!1000!.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

Find the largest integer kk such that 2k2^k divides 1000!500!\dfrac{1000!}{500!}.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Find the largest integer kk such that 2k2^k divides 31024−13^{1024} - 1.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 4

For how many integers kk with 0≤k≤20260 \le k \le 2026 is (2026k)\dbinom{2026}{k} odd?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Find the largest integer kk such that 7k7^k divides (20261013)\dbinom{2026}{1013}.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

Find the smallest positive integer nn such that 2n+12^n + 1 is divisible by 373^7.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

Find ∑n=1100v2 ⁣(3n−1)\displaystyle\sum_{n=1}^{100} v_2\!\left(3^n - 1\right).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

For how many positive integers n≤1000n \le 1000 is (2nn)\dbinom{2n}{n} not divisible by 88?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice

  • 2020 AIME I, Problem 12: the least nn with 149n−2n149^n - 2^n divisible by 33⋅55⋅773^3 \cdot 5^5 \cdot 7^7, a textbook LTE problem.
  • 1983 AIME, Problem 8: the largest two-digit prime factor of (200100)\binom{200}{100}, counting prime exponents in factorials.