MatheramaMatherama
← Combinatorics
Combinatorics·Section 2·21 min read

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:

  1. Divisor and factorial problems in elementary number theory.
  2. 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.


Number of Factors of a Positive Integer§

By the Fundamental Theorem of Arithmetic, every positive integer N>1N > 1 can be written uniquely as a product of prime powers:

N=p1n1p2n2p3n3⋯pknkN = p_1^{n_1} p_2^{n_2} p_3^{n_3} \cdots p_k^{n_k}

where p1,p2,…,pkp_1, p_2, \dots, p_k are distinct prime numbers and n1,n2,…,nkn_1, n_2, \dots, n_k are positive integers.

When is another positive integer MM a factor (divisor) of NN? Only when MM uses no primes outside {p1,…,pk}\{p_1, \dots, p_k\} and raises each prime pip_i to a power no larger than nin_i. That is, MM divides NN if and only if:

M=p1s1p2s2p3s3⋯pksk,0≤s1≤n1,  0≤s2≤n2,  …,  0≤sk≤nkM = p_1^{s_1} p_2^{s_2} p_3^{s_3} \cdots p_k^{s_k}, \qquad 0 \le s_1 \le n_1,\; 0 \le s_2 \le n_2,\; \dots,\; 0 \le s_k \le n_k

Look at the choices for each exponent:

  • s1s_1 can take any of the n1+1n_1 + 1 values {0,1,2,…,n1}\{0, 1, 2, \dots, n_1\}.
  • s2s_2 can take any of the n2+1n_2 + 1 values {0,1,2,…,n2}\{0, 1, 2, \dots, n_2\}.
  • In general, sis_i can take ni+1n_i + 1 values independently of every other exponent.

By the Multiplication Principle, the total number of positive factors of NN (denoted τ(N)\tau(N), including both 11 and NN) is:

τ(N)=(n1+1)(n2+1)(n3+1)⋯(nk+1)\tau(N) = (n_1 + 1)(n_2 + 1)(n_3 + 1) \cdots (n_k + 1)

Example 1: Find the total number of positive factors of N=72N = 72.

Solution: Factor 7272 into primes: 72=23⋅3272 = 2^3 \cdot 3^2. Any positive factor of 7272 has the form 2u3v2^u 3^v where 0≤u≤30 \le u \le 3 (44 choices) and 0≤v≤20 \le v \le 2 (33 choices). By the Multiplication Principle:

τ(72)=4×3=12\tau(72) = 4 \times 3 = 12

Notice that this count includes 1=20301 = 2^0 3^0 and 72=233272 = 2^3 3^2. If we exclude 7272, there are 1111 proper factors; if we exclude both 11 and 7272, there are 1010 non-trivial factors.

Example 2 (Common Factors via GCD): How many positive common factors do 360360 and 10,50010{,}500 share?

Solution: Write the prime factorizations of both numbers:

360=23⋅32⋅51,10,500=22⋅31⋅53⋅71360 = 2^3 \cdot 3^2 \cdot 5^1, \qquad 10{,}500 = 2^2 \cdot 3^1 \cdot 5^3 \cdot 7^1

A positive integer divides both 360360 and 10,50010{,}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\gcd(360, 10{,}500) = 2^2 \cdot 3^1 \cdot 5^1

Thus every common factor has the form 2u3v5w2^u 3^v 5^w with 0≤u≤20 \le u \le 2, 0≤v≤10 \le v \le 1, and 0≤w≤10 \le w \le 1. The total number of common factors (including 11) is:

(2+1)(1+1)(1+1)=3×2×2=12(2 + 1)(1 + 1)(1 + 1) = 3 \times 2 \times 2 = 12

Highest Power of a Prime in a Factorial (Legendre's Formula)§

For any positive integer nn, the factorial n!n! is the product 1×2×3×⋯×n1 \times 2 \times 3 \times \dots \times n. Suppose we want the prime factorization of a large factorial such as 15!15! or 100!100! without multiplying all the numbers out.

Theorem (Legendre's Formula): If pp is a prime number and n∈Nn \in \mathbb{N}, then the highest power of pp in the prime factorization of n!n!, denoted Ep(n!)E_p(n!), is:

Ep(n!)=⌊np⌋+⌊np2⌋+⌊np3⌋+…E_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 + \dots

where ⌊x⌋\lfloor x \rfloor (the greatest integer function) denotes the largest integer less than or equal to xx, and the sum stops once pm>np^m > n.

Proof: Consider the integers 1,2,3,…,n1, 2, 3, \dots, n whose product is n!n!:

  • Exactly ⌊n/p⌋\lfloor n / p \rfloor of these integers are multiples of pp; each contributes at least one factor of pp.
  • Among them, ⌊n/p2⌋\lfloor n / p^2 \rfloor are multiples of p2p^2; each contributes a second factor of pp beyond the first already counted.
  • In general, ⌊n/pm⌋\lfloor n / p^m \rfloor are multiples of pmp^m; each contributes an mm-th factor of pp.

Adding these counts totals the exact exponent of pp across every integer from 11 to nn with neither overcounting nor undercounting. ■\blacksquare

The figure below illustrates this stacking process for p=2p = 2 in 15!15!: every multiple of 22 gets a blue block, every multiple of 44 gets an additional green block, and every multiple of 88 gets a third red block, so each column's height equals the exact power of 22 dividing that integer:

Stacking Factors of 2 in 15! Illustrating Legendre's Formula

Why pp Must Be Prime:
Legendre's Formula works directly only for prime numbers pp. For a composite number like 6=2×36 = 2 \times 3 or 10=2×510 = 2 \times 5, two smaller integers (such as 22 and 33) can multiply together to form a factor of 66 even though neither is a multiple of 66. 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!15! and determine its total number of positive factors.

Solution: Every prime factor of 15!15! must be less than or equal to 1515, so the primes involved are 2,3,5,7,11,2, 3, 5, 7, 11, and 1313. Computing the exponent of each prime:

E2(15!)=⌊152⌋+⌊154⌋+⌊158⌋=7+3+1=11E_2(15!) = \left\lfloor \frac{15}{2} \right\rfloor + \left\lfloor \frac{15}{4} \right\rfloor + \left\lfloor \frac{15}{8} \right\rfloor = 7 + 3 + 1 = 11 E3(15!)=⌊153⌋+⌊159⌋=5+1=6E_3(15!) = \left\lfloor \frac{15}{3} \right\rfloor + \left\lfloor \frac{15}{9} \right\rfloor = 5 + 1 = 6 E5(15!)=⌊155⌋=3,E7(15!)=⌊157⌋=2,E11(15!)=1,E13(15!)=1E_5(15!) = \left\lfloor \frac{15}{5} \right\rfloor = 3, \qquad E_7(15!) = \left\lfloor \frac{15}{7} \right\rfloor = 2, \qquad E_{11}(15!) = 1, \qquad E_{13}(15!) = 1

Therefore:

15!=211⋅36⋅53⋅72⋅111⋅13115! = 2^{11} \cdot 3^6 \cdot 5^3 \cdot 7^2 \cdot 11^1 \cdot 13^1

The total number of positive factors of 15!15! is:

τ(15!)=(11+1)(6+1)(3+1)(2+1)(1+1)(1+1)=12×7×4×3×2×2=4032\tau(15!) = (11 + 1)(6 + 1)(3 + 1)(2 + 1)(1 + 1)(1 + 1) = 12 \times 7 \times 4 \times 3 \times 2 \times 2 = 4032

Example 4 (Composite Base): If 6k6^k divides 100!100!, what is the maximum integer value of kk?

Solution: Since 6k=2k⋅3k6^k = 2^k \cdot 3^k, we need both 2k2^k and 3k3^k to divide 100!100!. Computing the highest powers of 22 and 33 in 100!100!:

E2(100!)=⌊1002⌋+⌊1004⌋+⌊1008⌋+⌊10016⌋+⌊10032⌋+⌊10064⌋=50+25+12+6+3+1=97E_2(100!) = \left\lfloor \frac{100}{2} \right\rfloor + \left\lfloor \frac{100}{4} \right\rfloor + \left\lfloor \frac{100}{8} \right\rfloor + \left\lfloor \frac{100}{16} \right\rfloor + \left\lfloor \frac{100}{32} \right\rfloor + \left\lfloor \frac{100}{64} \right\rfloor = 50 + 25 + 12 + 6 + 3 + 1 = 97 E3(100!)=⌊1003⌋+⌊1009⌋+⌊10027⌋+⌊10081⌋=33+11+3+1=48E_3(100!) = \left\lfloor \frac{100}{3} \right\rfloor + \left\lfloor \frac{100}{9} \right\rfloor + \left\lfloor \frac{100}{27} \right\rfloor + \left\lfloor \frac{100}{81} \right\rfloor = 33 + 11 + 3 + 1 = 48

We can form at most min⁡(97,48)=48\min(97, 48) = 48 pairs of 2×32 \times 3. Hence the maximum integer value of kk is 4848.

Example 5 (Repeated Prime Factor in Composite Base): What is the highest power of 1212 that divides 50!50!?

Solution: Note that 12k=(22⋅3)k=22k⋅3k12^k = (2^2 \cdot 3)^k = 2^{2k} \cdot 3^k. We compute:

E2(50!)=25+12+6+3+1=47,E3(50!)=16+5+1=22E_2(50!) = 25 + 12 + 6 + 3 + 1 = 47, \qquad E_3(50!) = 16 + 5 + 1 = 22

Each factor of 1212 requires two 22's and one 33. The 4747 available factors of 22 supply ⌊47/2⌋=23\lfloor 47 / 2 \rfloor = 23 pairs of 222^2, while there are 2222 factors of 33. Thus k=min⁡(23,22)=22k = \min(23, 22) = 22.

Example 6 (Trailing Zeroes in a Factorial): Find the number of trailing zeroes at the end of 25!25!.

Solution: Each trailing zero corresponds to a factor of 10=2×510 = 2 \times 5. Because factors of 22 are always far more abundant than factors of 55 in any factorial, the number of trailing zeroes equals E5(25!)E_5(25!):

E5(25!)=⌊255⌋+⌊2525⌋=5+1=6E_5(25!) = \left\lfloor \frac{25}{5} \right\rfloor + \left\lfloor \frac{25}{25} \right\rfloor = 5 + 1 = 6

Hence 25!25! ends in 66 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 33 or 44.

Example 7 (Perfect Square Factors): How many positive factors of 64,80064{,}800 are perfect squares?

Solution: Factor 64,80064{,}800 into primes:

64,800=25⋅34⋅5264{,}800 = 2^5 \cdot 3^4 \cdot 5^2

A factor 2u3v5w2^u 3^v 5^w is a perfect square if and only if every prime exponent u,v,wu, v, w is even:

  • u∈{0,2,4}u \in \{0, 2, 4\} (33 choices),
  • v∈{0,2,4}v \in \{0, 2, 4\} (33 choices),
  • w∈{0,2}w \in \{0, 2\} (22 choices).

Since these exponent choices are independent, the number of perfect-square factors of 64,80064{,}800 is 3×3×2=183 \times 3 \times 2 = 18.

Example 8 (Factors in Arithmetic Residue Classes): How many positive factors of N=13,335,840,000N = 13{,}335{,}840{,}000 are of each form (for n∈Zn \in \mathbb{Z}): (a) 2n+12n + 1, (b) 4n4n, (c) 3n3n, (d) 3n+13n + 1, (e) 3n+23n + 2, (f) 4n+24n + 2, (g) 4n+14n + 1, (h) 4n+34n + 3?

Solution: Begin with the prime factorization:

N=13,335,840,000=28⋅35⋅54⋅73N = 13{,}335{,}840{,}000 = 2^8 \cdot 3^5 \cdot 5^4 \cdot 7^3

Any positive factor of NN has the form 2u3v5w7z2^u 3^v 5^w 7^z where 0≤u≤80 \le u \le 8, 0≤v≤50 \le v \le 5, 0≤w≤40 \le w \le 4, and 0≤z≤30 \le z \le 3. Note that the total number of factors is τ(N)=9×6×5×4=1080\tau(N) = 9 \times 6 \times 5 \times 4 = 1080, which we can use to cross-check our answers!

(a) Form 2n+12n + 1 (Odd factors): An odd integer cannot contain the prime factor 22, so we must set u=0u = 0 (11 choice), while v,w,zv, w, z remain unrestricted:

1×6×5×4=1201 \times 6 \times 5 \times 4 = 120

(b) Form 4n4n (Multiples of 44): A multiple of 4=224 = 2^2 must have 2≤u≤82 \le u \le 8 (77 choices), while v,w,zv, w, z are unrestricted:

7×6×5×4=8407 \times 6 \times 5 \times 4 = 840

(c) Form 3n3n (Multiples of 33): A multiple of 33 must have 1≤v≤51 \le v \le 5 (55 choices), while u,w,zu, w, z are unrestricted:

9×5×5×4=9009 \times 5 \times 5 \times 4 = 900

(d) Form 3n+13n + 1: Every integer belongs to exactly one of three remainder classes upon division by 33: 3k3k, 3k+13k + 1, or 3k+23k + 2. Check our four primes: 33 is of the form 3k3k, 77 is of the form 3k+13k + 1, while 22 and 55 are of the form 3k+23k + 2.

Observe how numbers from these classes behave when multiplied:

(3n+2)(3m+2)=9mn+6n+6m+4=3(3mn+2n+2m+1)+1=3k+1(3n + 2)(3m + 2) = 9mn + 6n + 6m + 4 = 3(3mn + 2n + 2m + 1) + 1 = 3k + 1 (3n+1)(3m+2)=3(3mn+2n+m)+2=3k+2(3n + 1)(3m + 2) = 3(3mn + 2n + m) + 2 = 3k + 2 (3n+1)(3m+1)=3(3mn+n+m)+1=3k+1(3n + 1)(3m + 1) = 3(3mn + n + m) + 1 = 3k + 1

From these identities we draw four exact rules:

  1. Multiplying two numbers of form 3n+23n + 2 yields a number of form 3n+13n + 1 (e.g., 5×8=40=3(13)+15 \times 8 = 40 = 3(13) + 1).
  2. Multiplying a number of form 3n+13n + 1 by one of form 3n+23n + 2 yields a number of form 3n+23n + 2.
  3. Multiplying any number of factors of form 3n+13n + 1 always stays in form 3n+13n + 1.
  4. Multiplying any integer by a multiple of 33 yields a multiple of 33.

Therefore, a factor 2u3v5w7z2^u 3^v 5^w 7^z has the form 3n+13n + 1 if and only if:

  • v=0v = 0 (no prime factor 33),
  • z∈{0,1,2,3}z \in \{0, 1, 2, 3\} is arbitrary (44 choices, since every power of 77 stays in form 3n+13n + 1), and
  • u+wu + w is even (the primes of form 3n+23n + 2, namely 22 and 55, must pair up an even number of times).

Because u+wu + w is even when either both u,wu, w are even or both are odd, we partition into two disjoint cases:

  • Case 1 (u∈{0,2,4,6,8}u \in \{0, 2, 4, 6, 8\} even, w∈{0,2,4}w \in \{0, 2, 4\} even, z∈{0,1,2,3}z \in \{0, 1, 2, 3\}): 5×3×4=605 \times 3 \times 4 = 60.
  • Case 2 (u∈{1,3,5,7}u \in \{1, 3, 5, 7\} odd, w∈{1,3}w \in \{1, 3\} odd, z∈{0,1,2,3}z \in \{0, 1, 2, 3\}): 4×2×4=324 \times 2 \times 4 = 32.

Adding both cases gives 60+32=9260 + 32 = 92 factors of the form 3n+13n + 1.

(e) Form 3n+23n + 2: By the exact same analysis, we require v=0v = 0, z∈{0,1,2,3}z \in \{0, 1, 2, 3\} arbitrary, and u+wu + w odd (one exponent even, the other odd):

  • Case 1 (u∈{0,2,4,6,8}u \in \{0, 2, 4, 6, 8\} even, w∈{1,3}w \in \{1, 3\} odd, zz arbitrary): 5×2×4=405 \times 2 \times 4 = 40.
  • Case 2 (u∈{1,3,5,7}u \in \{1, 3, 5, 7\} odd, w∈{0,2,4}w \in \{0, 2, 4\} even, zz arbitrary): 4×3×4=484 \times 3 \times 4 = 48.

Total factors of the form 3n+23n + 2: 40+48=8840 + 48 = 88. (Cross-check: 900+92+88=1080=τ(N)900 + 92 + 88 = 1080 = \tau(N).)

(f) Form 4n+24n + 2: Since 4n+2=2(2n+1)4n + 2 = 2(2n + 1), a factor has this form if and only if it is divisible by 22 exactly once—that is, u=1u = 1 (11 choice), with v,w,zv, w, z unrestricted:

1×6×5×4=1201 \times 6 \times 5 \times 4 = 120

(g) Form 4n+14n + 1: Check how odd classes multiply modulo 44:

(4n+1)(4m+1)=4k+1,(4n+3)(4m+3)=4k+1,(4n+1)(4m+3)=4k+3(4n + 1)(4m + 1) = 4k + 1, \qquad (4n + 3)(4m + 3) = 4k + 1, \qquad (4n + 1)(4m + 3) = 4k + 3

Among our primes, 22 is even (4k+24k + 2), 55 is of the form 4k+14k + 1, while 33 and 77 are of the form 4k+34k + 3. Hence a factor 2u3v5w7z2^u 3^v 5^w 7^z has the form 4n+14n + 1 if and only if u=0u = 0 (odd), w∈{0,1,2,3,4}w \in \{0, 1, 2, 3, 4\} is arbitrary (55 choices), and v+zv + z is even:

  • Case 1 (v∈{0,2,4}v \in \{0, 2, 4\} even, z∈{0,2}z \in \{0, 2\} even, ww arbitrary): 3×2×5=303 \times 2 \times 5 = 30.
  • Case 2 (v∈{1,3,5}v \in \{1, 3, 5\} odd, z∈{1,3}z \in \{1, 3\} odd, ww arbitrary): 3×2×5=303 \times 2 \times 5 = 30.

Total factors of the form 4n+14n + 1: 30+30=6030 + 30 = 60.

(h) Form 4n+34n + 3: Same setup with u=0u = 0, ww arbitrary, and v+zv + z odd:

  • Case 1 (v∈{0,2,4}v \in \{0, 2, 4\} even, z∈{1,3}z \in \{1, 3\} odd, ww arbitrary): 3×2×5=303 \times 2 \times 5 = 30.
  • Case 2 (v∈{1,3,5}v \in \{1, 3, 5\} odd, z∈{0,2}z \in \{0, 2\} even, ww arbitrary): 3×2×5=303 \times 2 \times 5 = 30.

Total factors of the form 4n+34n + 3: 30+30=6030 + 30 = 60. (Cross-check: 840+120+60+60=1080=τ(N)840 + 120 + 60 + 60 = 1080 = \tau(N).)


Sum and Product of All Factors of a Number§

Having counted how many factors a positive integer NN 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⋯pknkN = p_1^{n_1} p_2^{n_2} \cdots p_k^{n_k}, then the sum σ(N)\sigma(N) of all positive factors of NN is:

σ(N)=(1+p1+p12+⋯+p1n1)(1+p2+⋯+p2n2)⋯(1+pk+⋯+pknk)\sigma(N) = \left(1 + p_1 + p_1^2 + \dots + p_1^{n_1}\right)\left(1 + p_2 + \dots + p_2^{n_2}\right) \cdots \left(1 + p_k + \dots + p_k^{n_k}\right) =(p1n1+1−1p1−1)(p2n2+1−1p2−1)⋯(pknk+1−1pk−1)= \left(\frac{p_1^{n_1 + 1} - 1}{p_1 - 1}\right)\left(\frac{p_2^{n_2 + 1} - 1}{p_2 - 1}\right) \cdots \left(\frac{p_k^{n_k + 1} - 1}{p_k - 1}\right)

Proof: By definition, every factor of NN has the form p1u1p2u2⋯pkukp_1^{u_1} p_2^{u_2} \cdots p_k^{u_k} with 0≤ui≤ni0 \le u_i \le n_i. Summing over all valid exponent tuples and factoring out each independent summation:

σ(N)=∑u1=0n1∑u2=0n2⋯∑uk=0nkp1u1p2u2⋯pkuk=(∑u1=0n1p1u1)(∑u2=0n2p2u2)⋯(∑uk=0nkpkuk)\sigma(N) = \sum_{u_1=0}^{n_1} \sum_{u_2=0}^{n_2} \cdots \sum_{u_k=0}^{n_k} p_1^{u_1} p_2^{u_2} \cdots p_k^{u_k} = \left(\sum_{u_1=0}^{n_1} p_1^{u_1}\right)\left(\sum_{u_2=0}^{n_2} p_2^{u_2}\right) \cdots \left(\sum_{u_k=0}^{n_k} p_k^{u_k}\right)

Each parenthesized factor is a finite geometric progression with ratio pip_i, yielding pini+1−1pi−1\frac{p_i^{n_i + 1} - 1}{p_i - 1}. ■\blacksquare

Theorem (Product of Positive Factors): If NN has τ(N)\tau(N) positive factors, then the product P(N)P(N) of all positive factors of NN is:

P(N)=Nτ(N)/2P(N) = N^{\tau(N)/2}

Proof: List all positive factors of NN in increasing order: d1,d2,…,dτd_1, d_2, \dots, d_{\tau}. Notice that as djd_j runs through all factors from smallest to largest, the complementary factor N/djN / d_j runs through the exact same set of factors from largest to smallest. Multiplying both lists together:

P(N)2=(∏j=1τdj)(∏j=1τNdj)=∏j=1τ(dj⋅Ndj)=∏j=1τN=Nτ(N)P(N)^2 = \left(\prod_{j=1}^{\tau} d_j\right)\left(\prod_{j=1}^{\tau} \frac{N}{d_j}\right) = \prod_{j=1}^{\tau} \left(d_j \cdot \frac{N}{d_j}\right) = \prod_{j=1}^{\tau} N = N^{\tau(N)}

Taking the positive square root yields P(N)=Nτ(N)/2P(N) = N^{\tau(N)/2}. ■\blacksquare

Example 9: Find the sum and product of all positive factors of N=24⋅35⋅53N = 2^4 \cdot 3^5 \cdot 5^3. Also find the sum of all even factors of NN.

Solution: First, τ(N)=(4+1)(5+1)(3+1)=120\tau(N) = (4 + 1)(5 + 1)(3 + 1) = 120.

The sum of all factors is:

σ(N)=(25−12−1)(36−13−1)(54−15−1)=31×364×156=1,760,304\sigma(N) = \left(\frac{2^5 - 1}{2 - 1}\right)\left(\frac{3^6 - 1}{3 - 1}\right)\left(\frac{5^4 - 1}{5 - 1}\right) = 31 \times 364 \times 156 = 1{,}760{,}304

The product of all factors is:

P(N)=N120/2=N60=(24⋅35⋅53)60=2240⋅3300⋅5180P(N) = N^{120/2} = N^{60} = \left(2^4 \cdot 3^5 \cdot 5^3\right)^{60} = 2^{240} \cdot 3^{300} \cdot 5^{180}

For the sum of all even factors, the exponent of 22 must be at least 11, so we simply omit 20=12^0 = 1 from the first geometric sum:

σeven(N)=(21+22+23+24)(36−12)(54−14)=30×364×156=1,703,520\sigma_{\text{even}}(N) = \left(2^1 + 2^2 + 2^3 + 2^4\right)\left(\frac{3^6 - 1}{2}\right)\left(\frac{5^4 - 1}{4}\right) = 30 \times 364 \times 156 = 1{,}703{,}520

Forming Numbers from Digits§

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 44-digit numbers can be formed using the digits A={1,2,3,4,5,6,7,8,9}A = \{1, 2, 3, 4, 5, 6, 7, 8, 9\} without repetition?

Solution: A 44-digit number has four places: thousands, hundreds, tens, and units. Filling them from left to right:

  • The thousands place can be filled in 99 ways.
  • Because repetition is forbidden, one digit has been used, so whatever digit sits in the thousands place, there are always 88 choices left for the hundreds place.
  • Similarly, there are always 77 choices for the tens place and 66 choices for the units place.

Because each choice count is independent of earlier choices, the Multiplication Principle gives:

9×8×7×6=30249 \times 8 \times 7 \times 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 44-digit numbers can be formed using {1,2,3,4,5,6,7,8,9}\{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}\{1, 3, 5, 7, 9\} (55 choices). Fill the units place first (55 ways). Now the tens place has 88 remaining digits, the hundreds place has 77, and the thousands place has 66—always independent of which odd digit was placed at the units place:

5×8×7×6=16805 \times 8 \times 7 \times 6 = 1680

(b) Even: Fill the units place first from {2,4,6,8}\{2, 4, 6, 8\} (44 choices), then the remaining three places in 8×7×68 \times 7 \times 6 ways:

4×8×7×6=13444 \times 8 \times 7 \times 6 = 1344

(Cross-check: 1680+1344=30241680 + 1344 = 3024.)

Why Filling the Wrong Place First Breaks Multiplication:
In part (a), suppose you had filled the tens place first (99 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, 55 odd digits remain; if it was odd, only 44 odd digits remain. The partition becomes uneven, breaking direct multiplication. Filling the constrained units place first keeps every subsequent count constant.

Introducing Zero: Competing Constraints§

Now complicate the digit set by adding 00. Zero introduces a second constraint: the leftmost (thousands) place cannot be 00, or else the number collapses into a 33-digit number.

Example 12 (Parity with Zero Included): How many 44-digit numbers can be formed using {0,1,2,3,4,5,6,7,8,9}\{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:

  1. Units place (1st): Must be odd {1,3,5,7,9}\{1, 3, 5, 7, 9\} (55 ways). Notice that 00 is never used here.
  2. Thousands place (2nd): Cannot be 00, and cannot be the odd digit just used at the units place. Because those two excluded digits are always distinct, there are always 88 choices left for the thousands place!
  3. Hundreds place (3rd): Two digits have been used, and 00 is now allowed: 88 choices.
  4. Tens place (4th): Three digits have been used: 77 choices.

Slot Diagram Showing Constraint Priority for 4-Digit Odd Numbers

By the Multiplication Principle:

Odd 4-digit numbers=5×8×8×7=2240\text{Odd 4-digit numbers} = 5 \times 8 \times 8 \times 7 = 2240

(b) Even: Try the same strategy—fill the units place from {0,2,4,6,8}\{0, 2, 4, 6, 8\} (55 ways) and then move to the thousands place. Here direct multiplication breaks down! Why? Because of 00:

  • If 00 was placed at the units place, 00 is already gone, leaving 99 choices for the thousands place.
  • If 2,4,6,2, 4, 6, or 88 was placed at the units place, both 00 and that even digit are unavailable for the thousands place, leaving only 88 choices.

Because the count at the thousands place depends on whether the units digit is 00, we partition all even 44-digit numbers into two disjoint, exhaustive cases:

Case Split Diagram for 4-Digit Even Numbers with Zero Included

  • Case I (Ends in 00): Units =1= 1 way (00), thousands =9= 9 ways, hundreds =8= 8 ways, tens =7= 7 ways   ⟹  1×9×8×7=504\implies 1 \times 9 \times 8 \times 7 = 504.
  • Case II (Ends in 2,4,6,2, 4, 6, or 88): Units =4= 4 ways, thousands =8= 8 ways (neither 00 nor the units digit), hundreds =8= 8 ways (00 is now allowed), tens =7= 7 ways   ⟹  4×8×8×7=1792\implies 4 \times 8 \times 8 \times 7 = 1792.

By the Addition Principle:

Even 4-digit numbers=504+1792=2296\text{Even 4-digit numbers} = 504 + 1792 = 2296

(Cross-check: Total 44-digit numbers from {0,…,9}\{0, \dots, 9\} without repetition =9×9×8×7=4536= 9 \times 9 \times 8 \times 7 = 4536, and 2240+2296=45362240 + 2296 = 4536.)

Example 13 (Numbers Greater Than a Threshold): How many 44-digit numbers greater than 40004000 can be formed using the digits {0,2,3,4,5,7}\{0, 2, 3, 4, 5, 7\} without repetition such that the number is divisible by 55?

Solution: To exceed 40004000, the thousands digit must belong to {4,5,7}\{4, 5, 7\}. To be divisible by 55, the units digit must belong to {0,5}\{0, 5\}. Notice that 55 appears in both constrained sets, creating a dependence between the two positions! Partition based on the units digit:

  • Case I (Units digit is 00): Units =1= 1 way (00). Thousands can be any of {4,5,7}\{4, 5, 7\} (33 ways). Remaining 44 digits fill hundreds and tens in 4×3=124 \times 3 = 12 ways. Total =1×3×4×3=36= 1 \times 3 \times 4 \times 3 = 36.
  • Case II (Units digit is 55): Units =1= 1 way (55). Now 55 is unavailable for the thousands place, leaving {4,7}\{4, 7\} (22 ways). Remaining 44 digits fill hundreds and tens in 4×3=124 \times 3 = 12 ways. Total =1×2×4×3=24= 1 \times 2 \times 4 \times 3 = 24.

By the Addition Principle, there are 36+24=6036 + 24 = 60 such numbers.


Sum of All Numbers Formed by a Set of Digits§

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 nn-Digit Permutations of Distinct Non-Zero Digits): Given nn distinct non-zero digits d1,d2,…,dnd_1, d_2, \dots, d_n, the sum of all n!n! numbers formed by arranging them without repetition is:

S=(n−1)!⋅(d1+d2+⋯+dn)⋅11⋯1⏟n ones=(n−1)!⋅(d1+d2+⋯+dn)⋅10n−19S = (n - 1)! \cdot (d_1 + d_2 + \dots + d_n) \cdot \underbrace{11\cdots 1}_{n \text{ ones}} = (n - 1)! \cdot (d_1 + d_2 + \dots + d_n) \cdot \frac{10^n - 1}{9}

Proof: Fix any digit did_i in a specific place value 10j10^j (0≤j≤n−10 \le j \le n - 1). The remaining n−1n - 1 digits permute in the remaining n−1n - 1 positions in (n−1)!(n - 1)! ways. Hence every digit did_i appears exactly (n−1)!(n - 1)! times in the 10j10^j column. Summing the column contributions across all digits and all nn places:

S=∑j=0n−110j(∑i=1n(n−1)! di)=(n−1)!(∑i=1ndi)(1+10+102+⋯+10n−1)■S = \sum_{j=0}^{n-1} 10^j \left(\sum_{i=1}^{n} (n - 1)! \, d_i\right) = (n - 1)! \left(\sum_{i=1}^{n} d_i\right)\left(1 + 10 + 10^2 + \dots + 10^{n-1}\right) \qquad \blacksquare

Example 14: Find the sum of all 44-digit numbers formed using the digits {1,3,5,7}\{1, 3, 5, 7\} without repetition.

Solution: Here n=4n = 4 and 1+3+5+7=161 + 3 + 5 + 7 = 16. Each digit appears 3!=63! = 6 times in each of the four places:

S=3!×16×1111=6×16×1111=106,656S = 3! \times 16 \times 1111 = 6 \times 16 \times 1111 = 106{,}656

Example 15 (Sum When Zero Is Included): Find the sum of all 44-digit numbers formed using {0,2,4,6}\{0, 2, 4, 6\} without repetition.

Solution: Use the Subtraction Principle! First pretend 00 is permitted in the thousands place—this sums all 4!=244! = 24 strings:

Sall=3!×(0+2+4+6)×1111=6×12×1111=79,992S_{\text{all}} = 3! \times (0 + 2 + 4 + 6) \times 1111 = 6 \times 12 \times 1111 = 79{,}992

Now subtract the invalid strings that begin with 00. Dropping the leading 00 leaves precisely all 33-digit numbers formed from {2,4,6}\{2, 4, 6\}:

Sleading 0=2!×(2+4+6)×111=2×12×111=2664S_{\text{leading } 0} = 2! \times (2 + 4 + 6) \times 111 = 2 \times 12 \times 111 = 2664

Therefore, the required sum is:

S=79,992−2664=77,328S = 79{,}992 - 2664 = 77{,}328

Summary Table§

Problem / Quantity Formula / Method Key Condition
Number of factors of N=∏i=1kpiniN = \prod_{i=1}^k p_i^{n_i} τ(N)=∏i=1k(ni+1)\tau(N) = \prod_{i=1}^k (n_i + 1) Includes 11 and NN
Common factors of AA and BB τ(gcd⁡(A,B))\tau(\gcd(A, B)) Factor both into primes first
Highest power of prime pp in n!n! Ep(n!)=∑m≥1⌊n/pm⌋E_p(n!) = \sum_{m \ge 1} \lfloor n / p^m \rfloor pp must be prime
Sum of positive factors of NN σ(N)=∏i=1kpini+1−1pi−1\sigma(N) = \prod_{i=1}^k \frac{p_i^{n_i + 1} - 1}{p_i - 1} Omit p0=1p^0 = 1 if factor must be divisible by pp
Product of positive factors of NN P(N)=Nτ(N)/2P(N) = N^{\tau(N)/2} Pairs each dd with N/dN / d
Digit formation with 00 and parity Fill most constrained place first; split cases when 00 overlaps constraints Prevents uneven partitions
Sum of all nn-digit numbers (distinct non-zero) (n−1)!(∑di)10n−19(n - 1)! \left(\sum d_i\right) \frac{10^n - 1}{9} Subtract leading-00 sum if 00 is in the set
Section 2 of 11 · Combinatorics

Mark this section complete when you have worked through its proofs.