Many AIME questions ask "what is the largest power of p dividing this number?" The number might be 1000!, a binomial coefficient like (10132026), or a difference of powers like 72048−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±bn.
Valuations
Definition
p-adic valuation
For a prime p and a nonzero integer n, vp(n) is the exponent of p in the prime factorization of n: the largest k with pk∣n.
For example, v2(48)=4 and v3(48)=1. Valuations turn multiplication into addition: vp(ab)=vp(a)+vp(b). For sums there is only an inequality, vp(a+b)≥min(vp(a),vp(b)), with equality when vp(a)=vp(b).
Legendre's formula
Legendre's formula
vp(n!)=⌊pn⌋+⌊p2n⌋+⌊p3n⌋+⋯=p−1n−sp(n),
where sp(n) is the sum of the base-p digits of n.
Why the first form.vp(n!)=∑k=1nvp(k). A number k with vp(k)=j should be counted j times. It is: once among the multiples of p, once among the multiples of p2, and so on up to pj. There are ⌊n/pi⌋ multiples of pi up to n.
Why the second form. Write n=∑dipi. Then ⌊n/pi⌋=di+di+1p+⋯. Summing over i≥1, digit dj contributes dj(1+p+⋯+pj−1)=djp−1pj−1. Adding up gives p−1n−sp(n).
The case p=2 is especially clean: v2(n!)=n−s2(n), where s2(n) is the number of 1s in binary.
Kummer's theorem
Kummer's theorem
vp((mm+n)) equals the number of carries when you add m and n in base p.
Why. By the digit form of Legendre,
vp(mm+n)=p−1sp(m)+sp(n)−sp(m+n).
Each carry reduces the digit sum by p−1 (a p in one column becomes a 1 in the next), so sp(m)+sp(n)−sp(m+n)=(p−1)⋅(carries).
A consequence: (kn) is not divisible by p for exactly ∏(di+1) values of k, where di are the base-p digits of n (those k whose digits are each at most n's, so there are no carries). This is Lucas's theorem. For p=2, the number of odd entries in row n of Pascal's triangle is 2s2(n). Also v2(n2n)=s2(n): adding n+n in binary carries once for every 1.
Lifting the exponent
Lifting the exponent (LTE)
Let p be an odd prime with p∣a−b and p∤a,b. Then for every n≥1,
vp(an−bn)=vp(a−b)+vp(n).
If also n is odd, then vp(an+bn)=vp(a+b)+vp(n) (when p∣a+b).
For p=2, with a,b odd and neven:
v2(an−bn)=v2(a−b)+v2(a+b)+v2(n)−1.
For n odd, simply v2(an−bn)=v2(a−b).
Proof for odd p. Two steps.
Step 1: if p∤n, vp(an−bn)=vp(a−b). Factor an−bn=(a−b)(an−1+an−2b+⋯+bn−1). Since a≡b(modp), the second factor is ≡nan−1≡0(modp).
Step 2: vp(ap−bp)=vp(a−b)+1. The second factor is S=∑i=0p−1ap−1−ibi. Write b=a+t with p∣t. Then ap−1−ibi≡ap−1+iap−2t(modp2), so
S≡pap−1+ap−2t⋅2p(p−1)(modp2).
The second term is divisible by p2 (since p∣t and p is odd, so 2p−1 is an integer), and the first is divisible by p exactly once. So vp(S)=1.
Now write n=pkm with p∤m and apply Step 2 k times and Step 1 once. The + version follows by replacing b with −b.
The p=2 case. For even n=2km with m odd, factor a2k−b2k=(a−b)(a+b)(a2+b2)(a4+b4)⋯(a2k−1+b2k−1). Each a2j+b2j with j≥1 is ≡2(mod4), contributing exactly one 2. That gives v2(a−b)+v2(a+b)+(k−1). The odd part m doesn't change the valuation (Step 1 again).
Common mistake
LTE needs p∣a−b (or p∣a+b for the plus version) andp∤ab. For p=2, the formula with v2(a+b) only holds for evenn. Check these conditions before applying it: v3(2n−1) isn't v3(1)+v3(n), because 3∤2−1.
Worked example: Legendre two ways
Find v2(100!).
Floors: 50+25+12+6+3+1=97. Digits: 100=11001002 has three 1s, so v2(100!)=100−3=97.
Worked example: Kummer
Find v3((50100)).
50=12123 (since 27+2⋅9+3+2=50). Add 12123+12123: units 2+2=4=1⋅3+1, carry; threes 1+1+1=3, carry; nines 2+2+1=5, carry; twenty-sevens 1+1+1=3, carry. Four carries, so v3=4 (the sum is 102013=100).
Worked example: LTE, odd prime
Find the largest k such that 3k∣481−1.
3∣4−1 and 3∤4, so v3(481−1)=v3(3)+v3(81)=1+4=5.
Worked example: LTE, p = 2
Find v2(764−1).
64 is even: v2(7−1)+v2(7+1)+v2(64)−1=1+3+6−1=9.
Practice
Practice 1
Find the largest integer k such that 3k divides 1000!.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 2
Find the largest integer k such that 2k divides 500!1000!.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 3
Find the largest integer k such that 2k divides 31024−1.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 4
For how many integers k with 0≤k≤2026 is (k2026) odd?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 5
Find the largest integer k such that 7k divides (10132026).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 6
Find the smallest positive integer n such that 2n+1 is divisible by 37.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 7
Find n=1∑100v2(3n−1).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 8
For how many positive integers n≤1000 is (n2n)not divisible by 8?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Real contest practice
2020 AIME I, Problem 12: the least n with 149n−2n divisible by 33⋅55⋅77, a textbook LTE problem.
1983 AIME, Problem 8: the largest two-digit prime factor of (100200), counting prime exponents in factorials.