Skip to content

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 > 1\) can be written uniquely as a product of prime powers:

\[N = p_1^{n_1} p_2^{n_2} p_3^{n_3} \cdots p_k^{n_k}\]

where \(p_1, p_2, \dots, p_k\) are distinct prime numbers and \(n_1, n_2, \dots, n_k\) are positive integers.

When is another positive integer \(M\) a factor (divisor) of \(N\)? Only when \(M\) uses no primes outside \(\{p_1, \dots, p_k\}\) and raises each prime \(p_i\) to a power no larger than \(n_i\). That is, \(M\) divides \(N\) if and only if:

\[M = 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:

  • \(s_1\) can take any of the \(n_1 + 1\) values \(\{0, 1, 2, \dots, n_1\}\).
  • \(s_2\) can take any of the \(n_2 + 1\) values \(\{0, 1, 2, \dots, n_2\}\).
  • In general, \(s_i\) can take \(n_i + 1\) values independently of every other exponent.

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

\[\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 = 72\).

Solution: Factor \(72\) into primes: \(72 = 2^3 \cdot 3^2\). Any positive factor of \(72\) has the form \(2^u 3^v\) where \(0 \le u \le 3\) (\(4\) choices) and \(0 \le v \le 2\) (\(3\) choices). By the Multiplication Principle:

\[\tau(72) = 4 \times 3 = 12\]

Notice that this count includes \(1 = 2^0 3^0\) and \(72 = 2^3 3^2\). If we exclude \(72\), there are \(11\) proper 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 = 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 \(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) = 2^2 \cdot 3^1 \cdot 5^1\]

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

\[(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 \(n\), the factorial \(n!\) is the product \(1 \times 2 \times 3 \times \dots \times 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 \in \mathbb{N}\), then the highest power of \(p\) in the prime factorization of \(n!\), denoted \(E_p(n!)\), is:

\[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 \(\lfloor x \rfloor\) (the greatest integer function) denotes the largest integer less than or equal to \(x\), and the sum stops once \(p^m > n\).

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

  • Exactly \(\lfloor n / p \rfloor\) of these integers are multiples of \(p\); each contributes at least one factor of \(p\).
  • Among them, \(\lfloor n / p^2 \rfloor\) are multiples of \(p^2\); each contributes a second factor of \(p\) beyond the first already counted.
  • In general, \(\lfloor n / p^m \rfloor\) are multiples of \(p^m\); 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. \(\blacksquare\)

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:

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

Why \(p\) Must Be Prime:
Legendre's Formula works directly only for prime numbers \(p\). For a composite number like \(6 = 2 \times 3\) or \(10 = 2 \times 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:

\[E_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\]
\[E_3(15!) = \left\lfloor \frac{15}{3} \right\rfloor + \left\lfloor \frac{15}{9} \right\rfloor = 5 + 1 = 6\]
\[E_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! = 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!\) is:

\[\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 \(6^k\) divides \(100!\), what is the maximum integer value of \(k\)?

Solution: Since \(6^k = 2^k \cdot 3^k\), we need both \(2^k\) and \(3^k\) to divide \(100!\). Computing the highest powers of \(2\) and \(3\) in \(100!\):

\[E_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\]
\[E_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\) pairs of \(2 \times 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 \(12^k = (2^2 \cdot 3)^k = 2^{2k} \cdot 3^k\). We compute:

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

Each factor of \(12\) requires two \(2\)'s and one \(3\). The \(47\) available factors of \(2\) supply \(\lfloor 47 / 2 \rfloor = 23\) pairs of \(2^2\), 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 \times 5\). Because factors of \(2\) are always far more abundant than factors of \(5\) in any factorial, the number of trailing zeroes equals \(E_5(25!)\):

\[E_5(25!) = \left\lfloor \frac{25}{5} \right\rfloor + \left\lfloor \frac{25}{25} \right\rfloor = 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 = 2^5 \cdot 3^4 \cdot 5^2\]

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

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

Since these exponent choices are independent, the number of perfect-square factors of \(64{,}800\) is \(3 \times 3 \times 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 \in \mathbb{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 = 2^8 \cdot 3^5 \cdot 5^4 \cdot 7^3\]

Any positive factor of \(N\) has the form \(2^u 3^v 5^w 7^z\) where \(0 \le u \le 8\), \(0 \le v \le 5\), \(0 \le w \le 4\), and \(0 \le z \le 3\). Note that the total number of factors is \(\tau(N) = 9 \times 6 \times 5 \times 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 \times 6 \times 5 \times 4 = 120\]

(b) Form \(4n\) (Multiples of \(4\)): A multiple of \(4 = 2^2\) must have \(2 \le u \le 8\) (\(7\) choices), while \(v, w, z\) are unrestricted:

\[7 \times 6 \times 5 \times 4 = 840\]

(c) Form \(3n\) (Multiples of \(3\)): A multiple of \(3\) must have \(1 \le v \le 5\) (\(5\) choices), while \(u, w, z\) are unrestricted:

\[9 \times 5 \times 5 \times 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:

\[(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 + 1) = 3(3mn + n + m) + 1 = 3k + 1\]

From these identities we draw four exact rules:

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

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

  • \(v = 0\) (no prime factor \(3\)),
  • \(z \in \{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 \in \{0, 2, 4, 6, 8\}\) even, \(w \in \{0, 2, 4\}\) even, \(z \in \{0, 1, 2, 3\}\)): \(5 \times 3 \times 4 = 60\).
  • Case 2 (\(u \in \{1, 3, 5, 7\}\) odd, \(w \in \{1, 3\}\) odd, \(z \in \{0, 1, 2, 3\}\)): \(4 \times 2 \times 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 \in \{0, 1, 2, 3\}\) arbitrary, and \(u + w\) odd (one exponent even, the other odd):

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

Total factors of the form \(3n + 2\): \(40 + 48 = 88\). (Cross-check: \(900 + 92 + 88 = 1080 = \tau(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 \times 6 \times 5 \times 4 = 120\]

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

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

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 \(2^u 3^v 5^w 7^z\) has the form \(4n + 1\) if and only if \(u = 0\) (odd), \(w \in \{0, 1, 2, 3, 4\}\) is arbitrary (\(5\) choices), and \(v + z\) is even:

  • Case 1 (\(v \in \{0, 2, 4\}\) even, \(z \in \{0, 2\}\) even, \(w\) arbitrary): \(3 \times 2 \times 5 = 30\).
  • Case 2 (\(v \in \{1, 3, 5\}\) odd, \(z \in \{1, 3\}\) odd, \(w\) arbitrary): \(3 \times 2 \times 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 + z\) odd:

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

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


Sum and Product of All Factors of a Number

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 = p_1^{n_1} p_2^{n_2} \cdots p_k^{n_k}\), then the sum \(\sigma(N)\) of all positive factors of \(N\) is:

\[\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)\]
\[= \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 \(N\) has the form \(p_1^{u_1} p_2^{u_2} \cdots p_k^{u_k}\) with \(0 \le u_i \le n_i\). Summing over all valid exponent tuples and factoring out each independent summation:

\[\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 \(p_i\), yielding \(\frac{p_i^{n_i + 1} - 1}{p_i - 1}\). \(\blacksquare\)

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

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

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

\[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^{\tau(N)/2}\). \(\blacksquare\)

Example 9: Find the sum and product of all positive factors of \(N = 2^4 \cdot 3^5 \cdot 5^3\). Also find the sum of all even factors of \(N\).

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

The sum of all factors is:

\[\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) = 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 \(2\) must be at least \(1\), so we simply omit \(2^0 = 1\) from the first geometric sum:

\[\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 \(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 \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 \(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 \times 8 \times 7 \times 6 = 1680\]

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

\[4 \times 8 \times 7 \times 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.

Introducing Zero: Competing Constraints

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:

  1. Units place (1st): Must be odd \(\{1, 3, 5, 7, 9\}\) (\(5\) ways). Notice that \(0\) is never used here.
  2. 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!
  3. Hundreds place (3rd): Two digits have been used, and \(0\) is now allowed: \(8\) choices.
  4. Tens place (4th): Three digits have been used: \(7\) choices.

Slot Diagram Showing Constraint Priority for 4-Digit Odd Numbers

By the Multiplication Principle:

\[\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\}\) (\(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 Split Diagram for 4-Digit Even Numbers with Zero Included

  • Case I (Ends in \(0\)): Units \(= 1\) way (\(0\)), thousands \(= 9\) ways, hundreds \(= 8\) ways, tens \(= 7\) ways \(\implies 1 \times 9 \times 8 \times 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 \(\implies 4 \times 8 \times 8 \times 7 = 1792\).

By the Addition Principle:

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

(Cross-check: Total \(4\)-digit numbers from \(\{0, \dots, 9\}\) without repetition \(= 9 \times 9 \times 8 \times 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 \times 3 = 12\) ways. Total \(= 1 \times 3 \times 4 \times 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 \times 3 = 12\) ways. Total \(= 1 \times 2 \times 4 \times 3 = 24\).

By the Addition Principle, there are \(36 + 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 \(n\)-Digit Permutations of Distinct Non-Zero Digits): Given \(n\) distinct non-zero digits \(d_1, d_2, \dots, d_n\), the sum of all \(n!\) numbers formed by arranging them without repetition is:

\[S = (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 \(d_i\) in a specific place value \(10^j\) (\(0 \le j \le n - 1\)). The remaining \(n - 1\) digits permute in the remaining \(n - 1\) positions in \((n - 1)!\) ways. Hence every digit \(d_i\) appears exactly \((n - 1)!\) times in the \(10^j\) column. Summing the column contributions across all digits and all \(n\) places:

\[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 \(4\)-digit numbers formed using the digits \(\{1, 3, 5, 7\}\) without repetition.

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

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

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

Solution: Use the Subtraction Principle! First pretend \(0\) is permitted in the thousands place—this sums all \(4! = 24\) strings:

\[S_{\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 \(0\). Dropping the leading \(0\) leaves precisely all \(3\)-digit numbers formed from \(\{2, 4, 6\}\):

\[S_{\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{,}328\]

Summary Table

Problem / Quantity Formula / Method Key Condition
Number of factors of \(N = \prod_{i=1}^k p_i^{n_i}\) \(\tau(N) = \prod_{i=1}^k (n_i + 1)\) Includes \(1\) and \(N\)
Common factors of \(A\) and \(B\) \(\tau(\gcd(A, B))\) Factor both into primes first
Highest power of prime \(p\) in \(n!\) \(E_p(n!) = \sum_{m \ge 1} \lfloor n / p^m \rfloor\) \(p\) must be prime
Sum of positive factors of \(N\) \(\sigma(N) = \prod_{i=1}^k \frac{p_i^{n_i + 1} - 1}{p_i - 1}\) Omit \(p^0 = 1\) if factor must be divisible by \(p\)
Product of positive factors of \(N\) \(P(N) = N^{\tau(N)/2}\) Pairs each \(d\) with \(N / d\)
Digit formation with \(0\) and parity Fill most constrained place first; split cases when \(0\) overlaps constraints Prevents uneven partitions
Sum of all \(n\)-digit numbers (distinct non-zero) \((n - 1)! \left(\sum d_i\right) \frac{10^n - 1}{9}\) Subtract leading-\(0\) sum if \(0\) is in the set