Some useful p-adic formulas
Lemma. Write n0 + n1 p + n2 p2 + . . . for the p-adic expansion of an integer n > 1. Then we
have the following statements about p-adic valuations and residues:
(1) The valuation of n! is
X n n − (n0 + n1 + n2 + . . . )
v(n!) = = .
pk p−1
k>1
(2) If v = v(n!) then the leading term in the p-adic expansion of n! is
(−1)v n0 ! n1 ! n2 ! . . . pv .
(3) The valuation of the binomial coefficient nk is the sum of the carry overs in the addition of
k and n − k.
(4) If nk is prime to p then its mod p residue is nk00 nk11 nk22 . . .
n
(5) The valuation of the binomial coefficient pk is n − v(k), for k > 1.
Proof: (1) Say that n = n0 + n1 p + · · · + nr pr . There are bn/pk c integers m 6 n divisible by
pk and bn/pk c − bn/pk+1 c integers m 6 n of valuation k. It follows that
X n n X n
v(n!) = k − k+1 = .
pk p pk
k>1 k>1
Using the fact that bn/pk c = ni pi−k , we derive the formula
P
i>k
n − (n0 + n1 + · · · + nr )
v(n!) = .
p−1
(2) See also [Ha], chapter 17, § 3. For a finite set M of positive integers, let M ! be the product
of the elements of M and write the p-adic leading term of M ! in the form µ(M )pv(M !) . Thus,
we want to prove that µ({1, . . . , n}) = (−1)v(n!) n0 ! . . . nr !. For this, it is enough to produce a
partition {1, . . . , n} = A0 t · · · t Ar such that
i−1
ni pp−1
µ(Ai ) = (−1) ni !.
Call Ai the set of integers m ∈ {1, . . . , n} such that mi+1 = ni+1 , . . . , mr = nr and either
v(m) = i or mi < ni . This is a partition because n is in Av(n) and no other, while if m < n,
there is a maximal i such that mi < ni and then m is in Ai and no other. The integers
m ∈ Ai with valuation i are determined by their i-th digit which satisfies 1 6 mi 6 ni and they
contribute to µ(Ai ) by a factor ni !. The integers m ∈ Ai with valuation k < i are determined
by their k-th to i-th digits which satisfy 1 6 mk 6 p − 1, 0 6 mj 6 p − 1 for k < j < i, and
0 6 mi 6 ni − 1. Using the fact that (p − 1)! ≡ −1 mod p, an immediate computation shows
i−k−1
that these m contribute to µ(Ai ) by a factor (−1)ni p . Finally the value for µ(Ai ) is as
announced.
1
(3) Let k = k0 + k1 p + · · · + kr pr and l = n − k = l0 + l1 p + · · · + lr pr . Run the p-adic addition
algorithm to add up k and l:
k0 + l0 = n0 + δ0 p with δ0 ∈ {0, 1},
k1 + l1 + δ0 = n1 + δ1 p with δ1 ∈ {0, 1},
.. ..
. .
kr + lr + δr−1 = nr + δr p with δr ∈ {0, 1},
nr+1 = δr
where δ0 , . . . , δr are the carry overs. Then the formula in (1) implies that (p − 1) times the
valuation of nk = k!n!l! is equal to
n − (n0 + · · · + nr+1 ) − k + (k0 + · · · + kr ) − l + (l0 + · · · + lr ) = (p − 1)(δ0 + · · · + δr ).
(4) By what we have just proved, nk is prime to p if and only if there are no nonzero carry
overs. If this holds, then ni = ki + li for all i. Then the leading term in the p-adic expansion of
the binomial coefficient, which in the present case is also the p-adic residue, is
n0 ! . . . n r ! n0 nr
= ... .
k0 ! . . . kr ! l0 ! . . . lr ! k0 kr
(5) If k = pn , the result is clear. If 1 6 k 6 pn , we have v(pn − k) = v(k). So taking valuations
in the equality n
p
k! = pn (pn − 1) . . . (pn − (k − 1))
k
n
gives v(k!) + v pk = n + v((k − 1)!), whence the result.
References
[Ha] H. Hasse, Number theory, Classics in Mathematics, Springer-Verlag (2002).