What is a factorial?
The factorial n! is the product of every whole number from 1 to n. So 5! is 1 × 2 × 3 × 4 × 5 = 120. It counts the number of ways n distinct items can be arranged in a row, which makes it the basic tool of combinatorics.
n! and the number of combinations. Above 170! the result exceeds what a number can hold.
The factorial n! is the product of every whole number from 1 to n. So 5! is 1 × 2 × 3 × 4 × 5 = 120. It counts the number of ways n distinct items can be arranged in a row, which makes it the basic tool of combinatorics.
An empty set can be arranged in exactly one way — by doing nothing — so the count is 1, not 0. The recurrence n! = n × (n − 1)! demands the same: at n = 1 it gives 1! = 1 × 0!, so 0! can only be 1. This is not a convention but the only consistent value.
Faster than any power function. 10! is already 3,628,800, 20! is roughly 2.4 × 10¹⁸, and 70! exceeds what an ordinary numeric type can hold. That is why combinatorial problems with a few dozen elements become impossible to brute-force very quickly.
In counting combinations and permutations: how many ways a team can be picked, how many distinct passwords are possible, how many routes exist in the travelling-salesman problem. Factorials also appear throughout probability and in the series used to compute the exponential and sine functions.