Math Fundamentals18 sections · 814 units
Open in Course

Computing Large Combinations

(Avoiding overflow)

For large n, computing n! directly causes overflow. Instead, compute C(n,k) = (n × (n-1) × ... × (n-k+1)) / (k × (k-1) × ... × 1).

Interleave multiplication and division: multiply by the next numerator term, then divide by the next denominator term. This keeps intermediate values smaller.

Example: C(10,3) = (10/1) × (9/2) × (8/3) = 10 × 4.5 × 2.67 = 120 (using exact division). This prevents overflow for large numbers.