Factorial
Calculate n!, trailing zeros, and scientific notation.
Integer Input
Enter a non-negative integer to compute factorial.
About this topic
Factorial (n!) The product of all positive integers up to n.
The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. It is fundamental in combinatorics and probability.
Key formulas & rules
- •Formula: n! = n × (n-1) × ... × 1
- •0! is defined as 1
- •Grows extremely fast (super-exponential)
- •Used in permutations and combinations
- •Only defined for non-negative integers
- •Calculated using BigInt for accuracy
Examples
| Input | Output | Note |
|---|---|---|
| 3! | 6 | 3×2×1 |
| 5! | 120 | 5×4×3×2×1 |
| 0! | 1 | By definition |
| 10! | 3,628,800 | Grows fast |
Real-world uses
Trailing Zeros Counting the number of zeros at the end of n!.
Trailing zeros in n! are created by multiplying factors of 10, which come from pairs of 2s and 5s. Since there are always more 2s than 5s, the number of trailing zeros is determined by the number of factors of 5.
Key formulas & rules
- •Counted via Legendre's formula
- •Formula: floor(n/5) + floor(n/25) + floor(n/125) + ...
- •Does not require calculating the full factorial
- •Useful for large n where n! overflows
- •Zero only occurs when n < 5
Examples
| Input | Output | Note |
|---|---|---|
| 5! | 1 zero | 120 |
| 10! | 2 zeros | 3,628,800 |
| 25! | 6 zeros | 5 + 1 |
| 4! | 0 zeros | 24 |
Real-world uses
Number of Digits Calculating the length of n! without computing it.
For very large factorials, finding the exact number of digits is done using the sum of logarithms: floor(log10(1) + log10(2) + ... + log10(n)) + 1.
Key formulas & rules
- •Uses properties of logarithms
- •Formula: ⌊log₁₀(n!)⌋ + 1
- •Avoids computing the full factorial
- •Scales logarithmically
- •Essential for BigInt limits
Examples
| Input | Output | Note |
|---|---|---|
| 5! | 3 digits | 120 |
| 10! | 7 digits | 3628800 |
| 50! | 65 digits | Huge number |
| 100! | 158 digits | Massive |
Real-world uses
Modes & formulas
Compute n!
0! is defined as 1. Trailing zeros are counted efficiently via Legendre's formula without computing the full factorial.