Number-Theoretic Counting and Digit Formation Problems
Before introducing formal formulas for permutations and combinations, let us put the Addition, Multiplication, and Subtraction principles from Section 01 to work on two classic problem families:
Divisor and factorial problems in elementary number theory.
Forming numbers from digits under parity, repetition, and leading-zero constraints.
Both families build real skill in recognizing independent choices, ordering constraints properly, and constructing clean, non-overlapping partitions.
By the Fundamental Theorem of Arithmetic, every positive integer N>1 can be written uniquely as a product of prime powers:
N=p1n1p2n2p3n3⋯pknk
where p1,p2,…,pk are distinct prime numbers and n1,n2,…,nk are positive integers.
When is another positive integer M a factor (divisor) of N? Only when M uses no primes outside {p1,…,pk} and raises each prime pi to a power no larger than ni. That is, M divides N if and only if:
s1 can take any of the n1+1 values {0,1,2,…,n1}.
s2 can take any of the n2+1 values {0,1,2,…,n2}.
In general, si can take ni+1 values independently of every other exponent.
By the Multiplication Principle, the total number of positive factors of N (denoted τ(N), including both 1 and N) is:
τ(N)=(n1+1)(n2+1)(n3+1)⋯(nk+1)
Example 1: Find the total number of positive factors of N=72.
Solution: Factor 72 into primes: 72=23⋅32. Any positive factor of 72 has the form 2u3v where 0≤u≤3 (4 choices) and 0≤v≤2 (3 choices). By the Multiplication Principle:
τ(72)=4×3=12
Notice that this count includes 1=2030 and 72=2332. If we exclude 72, there are 11proper factors; if we exclude both 1 and 72, there are 10 non-trivial factors.
Example 2 (Common Factors via GCD): How many positive common factors do 360 and 10,500 share?
Solution: Write the prime factorizations of both numbers:
360=23⋅32⋅51,10,500=22⋅31⋅53⋅71
A positive integer divides both 360 and 10,500 if and only if it divides their greatest common divisor (GCD). Taking the minimum exponent of each common prime gives:
gcd(360,10,500)=22⋅31⋅51
Thus every common factor has the form 2u3v5w with 0≤u≤2, 0≤v≤1, and 0≤w≤1. The total number of common factors (including 1) is:
(2+1)(1+1)(1+1)=3×2×2=12
Highest Power of a Prime in a Factorial (Legendre's Formula)§
For any positive integer n, the factorial n! is the product 1×2×3×⋯×n. Suppose we want the prime factorization of a large factorial such as 15! or 100! without multiplying all the numbers out.
Theorem (Legendre's Formula): If p is a prime number and n∈N, then the highest power of p in the prime factorization of n!, denoted Ep(n!), is:
Ep(n!)=⌊pn⌋+⌊p2n⌋+⌊p3n⌋+…
where ⌊x⌋ (the greatest integer function) denotes the largest integer less than or equal to x, and the sum stops once pm>n.
Proof: Consider the integers 1,2,3,…,n whose product is n!:
Exactly ⌊n/p⌋ of these integers are multiples of p; each contributes at least one factor of p.
Among them, ⌊n/p2⌋ are multiples of p2; each contributes a second factor of p beyond the first already counted.
In general, ⌊n/pm⌋ are multiples of pm; each contributes an m-th factor of p.
Adding these counts totals the exact exponent of p across every integer from 1 to n with neither overcounting nor undercounting. ■
The figure below illustrates this stacking process for p=2 in 15!: every multiple of 2 gets a blue block, every multiple of 4 gets an additional green block, and every multiple of 8 gets a third red block, so each column's height equals the exact power of 2 dividing that integer:
Why p Must Be Prime:
Legendre's Formula works directly only for prime numbersp. For a composite number like 6=2×3 or 10=2×5, two smaller integers (such as 2 and 3) can multiply together to form a factor of 6 even though neither is a multiple of 6. For composite bases, always factor into primes first and apply Legendre's Formula to each prime factor.
Example 3: Write the complete prime factorization of 15! and determine its total number of positive factors.
Solution: Every prime factor of 15! must be less than or equal to 15, so the primes involved are 2,3,5,7,11, and 13. Computing the exponent of each prime:
We can form at most min(97,48)=48 pairs of 2×3. Hence the maximum integer value of k is 48.
Example 5 (Repeated Prime Factor in Composite Base): What is the highest power of 12 that divides 50!?
Solution: Note that 12k=(22⋅3)k=22k⋅3k. We compute:
E2(50!)=25+12+6+3+1=47,E3(50!)=16+5+1=22
Each factor of 12 requires two2's and one3. The 47 available factors of 2 supply ⌊47/2⌋=23 pairs of 22, while there are 22 factors of 3. Thus k=min(23,22)=22.
Example 6 (Trailing Zeroes in a Factorial): Find the number of trailing zeroes at the end of 25!.
Solution: Each trailing zero corresponds to a factor of 10=2×5. Because factors of 2 are always far more abundant than factors of 5 in any factorial, the number of trailing zeroes equals E5(25!):
E5(25!)=⌊525⌋+⌊2525⌋=5+1=6
Hence 25! ends in 6 zeroes.
Counting Factors Under Structural and Arithmetic Conditions§
By restricting which prime exponents are allowed, we can count divisors that satisfy specific properties—such as being perfect squares, being odd, or leaving a prescribed remainder upon division by 3 or 4.
Example 7 (Perfect Square Factors): How many positive factors of 64,800 are perfect squares?
Solution: Factor 64,800 into primes:
64,800=25⋅34⋅52
A factor 2u3v5w is a perfect square if and only if every prime exponent u,v,w is even:
u∈{0,2,4} (3 choices),
v∈{0,2,4} (3 choices),
w∈{0,2} (2 choices).
Since these exponent choices are independent, the number of perfect-square factors of 64,800 is 3×3×2=18.
Example 8 (Factors in Arithmetic Residue Classes): How many positive factors of N=13,335,840,000 are of each form (for n∈Z): (a) 2n+1, (b) 4n, (c) 3n, (d) 3n+1, (e) 3n+2, (f) 4n+2, (g) 4n+1, (h) 4n+3?
Solution: Begin with the prime factorization:
N=13,335,840,000=28⋅35⋅54⋅73
Any positive factor of N has the form 2u3v5w7z where 0≤u≤8, 0≤v≤5, 0≤w≤4, and 0≤z≤3. Note that the total number of factors is τ(N)=9×6×5×4=1080, which we can use to cross-check our answers!
(a) Form 2n+1 (Odd factors): An odd integer cannot contain the prime factor 2, so we must set u=0 (1 choice), while v,w,z remain unrestricted:
1×6×5×4=120
(b) Form 4n (Multiples of 4): A multiple of 4=22 must have 2≤u≤8 (7 choices), while v,w,z are unrestricted:
7×6×5×4=840
(c) Form 3n (Multiples of 3): A multiple of 3 must have 1≤v≤5 (5 choices), while u,w,z are unrestricted:
9×5×5×4=900
(d) Form 3n+1: Every integer belongs to exactly one of three remainder classes upon division by 3: 3k, 3k+1, or 3k+2. Check our four primes: 3 is of the form 3k, 7 is of the form 3k+1, while 2 and 5 are of the form 3k+2.
Observe how numbers from these classes behave when multiplied:
Multiplying two numbers of form 3n+2 yields a number of form 3n+1 (e.g., 5×8=40=3(13)+1).
Multiplying a number of form 3n+1 by one of form 3n+2 yields a number of form 3n+2.
Multiplying any number of factors of form 3n+1 always stays in form 3n+1.
Multiplying any integer by a multiple of 3 yields a multiple of 3.
Therefore, a factor 2u3v5w7z has the form 3n+1 if and only if:
v=0 (no prime factor 3),
z∈{0,1,2,3} is arbitrary (4 choices, since every power of 7 stays in form 3n+1), and
u+w is even (the primes of form 3n+2, namely 2 and 5, must pair up an even number of times).
Because u+w is even when either both u,w are even or both are odd, we partition into two disjoint cases:
Case 1 (u∈{0,2,4,6,8} even, w∈{0,2,4} even, z∈{0,1,2,3}):5×3×4=60.
Case 2 (u∈{1,3,5,7} odd, w∈{1,3} odd, z∈{0,1,2,3}):4×2×4=32.
Adding both cases gives 60+32=92 factors of the form 3n+1.
(e) Form 3n+2: By the exact same analysis, we require v=0, z∈{0,1,2,3} arbitrary, and u+wodd (one exponent even, the other odd):
Case 1 (u∈{0,2,4,6,8} even, w∈{1,3} odd, z arbitrary):5×2×4=40.
Case 2 (u∈{1,3,5,7} odd, w∈{0,2,4} even, z arbitrary):4×3×4=48.
Total factors of the form 3n+2: 40+48=88. (Cross-check: 900+92+88=1080=τ(N).)
(f) Form 4n+2: Since 4n+2=2(2n+1), a factor has this form if and only if it is divisible by 2 exactly once—that is, u=1 (1 choice), with v,w,z unrestricted:
1×6×5×4=120
(g) Form 4n+1: Check how odd classes multiply modulo 4:
Among our primes, 2 is even (4k+2), 5 is of the form 4k+1, while 3 and 7 are of the form 4k+3. Hence a factor 2u3v5w7z has the form 4n+1 if and only if u=0 (odd), w∈{0,1,2,3,4} is arbitrary (5 choices), and v+z is even:
Case 1 (v∈{0,2,4} even, z∈{0,2} even, w arbitrary):3×2×5=30.
Case 2 (v∈{1,3,5} odd, z∈{1,3} odd, w arbitrary):3×2×5=30.
Total factors of the form 4n+1: 30+30=60.
(h) Form 4n+3: Same setup with u=0, w arbitrary, and v+zodd:
Case 1 (v∈{0,2,4} even, z∈{1,3} odd, w arbitrary):3×2×5=30.
Case 2 (v∈{1,3,5} odd, z∈{0,2} even, w arbitrary):3×2×5=30.
Total factors of the form 4n+3: 30+30=60. (Cross-check: 840+120+60+60=1080=τ(N).)
Having counted how many factors a positive integer N has, can we compute the sum and the product of all its factors without listing them? Remarkably, both have crisp closed forms.
Theorem (Sum of Positive Factors): If N=p1n1p2n2⋯pknk, then the sum σ(N) of all positive factors of N is:
Proof: By definition, every factor of N has the form p1u1p2u2⋯pkuk with 0≤ui≤ni. Summing over all valid exponent tuples and factoring out each independent summation:
Each parenthesized factor is a finite geometric progression with ratio pi, yielding pi−1pini+1−1. ■
Theorem (Product of Positive Factors): If N has τ(N) positive factors, then the product P(N) of all positive factors of N is:
P(N)=Nτ(N)/2
Proof: List all positive factors of N in increasing order: d1,d2,…,dτ. Notice that as dj runs through all factors from smallest to largest, the complementary factor N/dj runs through the exact same set of factors from largest to smallest. Multiplying both lists together:
In Section 01, we discovered through the captain-and-monitor example that when restrictions are present, the order in which we make choices matters. Forming numbers from digits is the sharpest training ground for this principle.
Example 10 (No Zero, No Repetition): How many 4-digit numbers can be formed using the digits A={1,2,3,4,5,6,7,8,9} without repetition?
Solution: A 4-digit number has four places: thousands, hundreds, tens, and units. Filling them from left to right:
The thousands place can be filled in 9 ways.
Because repetition is forbidden, one digit has been used, so whatever digit sits in the thousands place, there are always 8 choices left for the hundreds place.
Similarly, there are always 7 choices for the tens place and 6 choices for the units place.
Because each choice count is independent of earlier choices, the Multiplication Principle gives:
9×8×7×6=3024
Here, filling the four places in any other order would produce the exact same result because no position carries a special restriction.
Example 11 (Parity Constraint, Without Zero): How many 4-digit numbers can be formed using {1,2,3,4,5,6,7,8,9} without repetition that are (a) odd, (b) even?
Solution:
(a) Odd: The units place carries a restriction: it can only take {1,3,5,7,9} (5 choices). Fill the units place first (5 ways). Now the tens place has 8 remaining digits, the hundreds place has 7, and the thousands place has 6—always independent of which odd digit was placed at the units place:
5×8×7×6=1680
(b) Even: Fill the units place first from {2,4,6,8} (4 choices), then the remaining three places in 8×7×6 ways:
4×8×7×6=1344
(Cross-check: 1680+1344=3024.)
Why Filling the Wrong Place First Breaks Multiplication:
In part (a), suppose you had filled the tens place first (9 choices) and then moved to the units place. How many choices would remain for the units place? It depends! If the digit you put in the tens place was even, 5 odd digits remain; if it was odd, only 4 odd digits remain. The partition becomes uneven, breaking direct multiplication. Filling the constrained units place first keeps every subsequent count constant.
Now complicate the digit set by adding 0. Zero introduces a second constraint: the leftmost (thousands) place cannot be 0, or else the number collapses into a 3-digit number.
Example 12 (Parity with Zero Included): How many 4-digit numbers can be formed using {0,1,2,3,4,5,6,7,8,9} without repetition that are (a) odd, (b) even?
Solution:
(a) Odd: Can we choose an order of filling the four places so that the Multiplication Principle still applies directly? Yes! Prioritize the two constrained places:
Units place (1st): Must be odd {1,3,5,7,9} (5 ways). Notice that 0 is never used here.
Thousands place (2nd): Cannot be 0, and cannot be the odd digit just used at the units place. Because those two excluded digits are always distinct, there are always 8 choices left for the thousands place!
Hundreds place (3rd): Two digits have been used, and 0 is now allowed: 8 choices.
Tens place (4th): Three digits have been used: 7 choices.
By the Multiplication Principle:
Odd 4-digit numbers=5×8×8×7=2240
(b) Even: Try the same strategy—fill the units place from {0,2,4,6,8} (5 ways) and then move to the thousands place. Here direct multiplication breaks down! Why? Because of 0:
If 0 was placed at the units place, 0 is already gone, leaving 9 choices for the thousands place.
If 2,4,6, or 8 was placed at the units place, both 0 and that even digit are unavailable for the thousands place, leaving only 8 choices.
Because the count at the thousands place depends on whether the units digit is 0, we partition all even 4-digit numbers into two disjoint, exhaustive cases:
Case I (Ends in 0): Units =1 way (0), thousands =9 ways, hundreds =8 ways, tens =7 ways ⟹1×9×8×7=504.
Case II (Ends in 2,4,6, or 8): Units =4 ways, thousands =8 ways (neither 0 nor the units digit), hundreds =8 ways (0 is now allowed), tens =7 ways ⟹4×8×8×7=1792.
By the Addition Principle:
Even 4-digit numbers=504+1792=2296
(Cross-check: Total 4-digit numbers from {0,…,9} without repetition =9×9×8×7=4536, and 2240+2296=4536.)
Example 13 (Numbers Greater Than a Threshold): How many 4-digit numbers greater than 4000 can be formed using the digits {0,2,3,4,5,7} without repetition such that the number is divisible by 5?
Solution: To exceed 4000, the thousands digit must belong to {4,5,7}. To be divisible by 5, the units digit must belong to {0,5}. Notice that 5 appears in both constrained sets, creating a dependence between the two positions! Partition based on the units digit:
Case I (Units digit is 0): Units =1 way (0). Thousands can be any of {4,5,7} (3 ways). Remaining 4 digits fill hundreds and tens in 4×3=12 ways. Total =1×3×4×3=36.
Case II (Units digit is 5): Units =1 way (5). Now 5 is unavailable for the thousands place, leaving {4,7} (2 ways). Remaining 4 digits fill hundreds and tens in 4×3=12 ways. Total =1×2×4×3=24.
By the Addition Principle, there are 36+24=60 such numbers.
A closely related problem asks not how many numbers can be formed by permuting a set of digits, but what their total sum is. Instead of listing the numbers and adding vertically, count how many times each digit occupies each place value (units, tens, hundreds, ...).
Theorem (Sum of All n-Digit Permutations of Distinct Non-Zero Digits): Given n distinct non-zero digits d1,d2,…,dn, the sum of all n! numbers formed by arranging them without repetition is:
Proof: Fix any digit di in a specific place value 10j (0≤j≤n−1). The remaining n−1 digits permute in the remaining n−1 positions in (n−1)! ways. Hence every digit di appears exactly (n−1)! times in the 10j column. Summing the column contributions across all digits and all n places: