Factorial Calculator: n!, Gamma function, Stirling approximation
Factorial calculator n! for integers up to 170. Gamma function Γ(x) for reals, Stirling, double factorial n!!, subfactorial !n. Permutations, combinations.
Report a calculation error
Help us improve. Describe what is wrong with the calculation.
Result
| Voce | Valore |
|---|
Show full details
Share result
Disclaimer: this calculation is for informational purposes only. For important decisions, consult a qualified professional.
Factorial: n! = n · (n−1) · ... · 1
The factorial of a positive integer n (written n!) is the product of all integers from 1 to n. Convention: 0! = 1. Explosive growth: 10! = 3,628,800, 20! ≈ 2.4 × 10¹⁸, 170! ≈ 7.3 × 10³⁰⁶ (double precision limit). Beyond, use Gamma function or BigInt. This calculator has 5 modes: integer factorial, double factorial n!!, subfactorial !n, Gamma Γ(x) for reals, Stirling approximation.
Fundamental formulas
- n! = n · (n−1)! (recursive) with 0! = 1
- n! = ∏ᵢ₌₁ⁿ i
- Γ(n) = (n−1)! for positive integers
- Stirling: n! ≈ √(2πn) · (n/e)ⁿ
- Double: n!! = n·(n−2)·(n−4)·...
- Subfactorial: !n = n!·Σₖ (−1)ᵏ/k!
Common factorials
| n | n! | Digits |
|---|---|---|
| 0 | 1 | 1 |
| 5 | 120 | 3 |
| 10 | 3,628,800 | 7 |
| 20 | 2.43×10¹⁸ | 19 |
| 50 | 3.04×10⁶⁴ | 65 |
| 100 | 9.33×10¹⁵⁷ | 158 |
| 170 | 7.26×10³⁰⁶ | 307 (double limit) |
Examples
Example 1: permutations of 6
Arranging 6 people in a row: 6! = 720 ways.
Example 2: lottery combinations
Pick 6 from 90 (Superenalotto): C(90,6) = 622,614,630. Probability: 1 in 622M.
Example 3: card deck
52 cards shuffles: 52! ≈ 8.07 × 10⁶⁷. More than atoms on Earth (10⁵⁰).
Example 4: derangement
5 people hat swap: !5 = 44. ~37% of permutations are derangements.
Example 5: Stirling for n=20
Exact: 20! = 2,432,902,008,176,640,000. Stirling ~2.42×10¹⁸. Error ~0.42%.
Gamma function Γ(x)
Extension of factorial to reals/complexes:
- Γ(n+1) = n! for positive integers
- Γ(1/2) = √π ≈ 1.7725
- Γ(x+1) = x·Γ(x)
- Poles at 0, −1, −2, ...
Introduced by Euler 1729. Numeric via Lanczos (15 digits precision).
Stirling approximation (1730)
n! ≈ √(2πn) · (n/e)ⁿ
More accurate: ·(1 + 1/(12n) + 1/(288n²) − ...).
Error: ~1/(12n). n=10: 0.83%. n=100: 0.083%. Used in asymptotic analysis, statistical mechanics, number theory.
Double factorial n!!
Product of same-parity integers: n!! = n·(n−2)·(n−4)·...
Examples: 5!! = 5·3·1 = 15. 6!! = 48. 10!! = 3840.
Relations: (2n)!! = 2ⁿ·n!. Used in combinatorics (Dyck paths), physics (Gauss moment integrals).
Subfactorial !n
Counts permutations without fixed points (derangements):
!n = n!·Σₖ (−1)ᵏ/k!
Values: !1=0, !2=1, !3=2, !4=9, !5=44, !6=265.
lim !n/n! = 1/e ≈ 0.3679. 37% of any random permutation is a derangement.
Hat problem
N people deposit hats at entrance. Exit randomly. Probability nobody gets their own = !N/N! → 1/e as N→∞. 36.79% at infinity.
Permutations and combinations
- P(n,k) = n!/(n−k)! — ordered selections
- C(n,k) = n!/(k!·(n−k)!) — unordered selections
- Binomial (ⁿₖ) = C(n,k)
Example: lottery 6/49 → C(49,6) = 13,983,816 possibilities.
Applications
Combinatorics and probability
- Lotteries (SuperEnalotto, Powerball, EuroMillions)
- Poker: C(52,5) = 2,598,960 hands
- Passwords
- Graph paths
- Anagrams
Statistics
- Poisson: P(k) = e^(−λ)·λᵏ/k!
- Binomial: C(n,k)·pᵏ·(1−p)^(n−k)
- Chi-square
Physics and chemistry
- Statistical mechanics: S = k·log(Ω)
- Quantum mechanics
- Taylor series: e^x = Σ xⁿ/n!
- Special functions (Bessel, Legendre)
Computer science
- Recursive algorithms
- O(n!) complexity: traveling salesman brute force
- Permutation generation
Engineering
- Maxwell-Boltzmann distribution
- Statistical quality control
- System reliability
Taylor series with factorials
- e^x = Σ xⁿ/n!
- sin(x) = Σ (−1)ⁿ x^(2n+1)/(2n+1)!
- cos(x) = Σ (−1)ⁿ x^(2n)/(2n)!
- (1+x)^α = Σ C(α,n)·xⁿ
History
Clavius (1603): first use in recreational math.
Kramp (1808): introduces "n!" notation.
Euler (1729): extends to Gamma function for reals. Extraordinary feat: generalizing n! to all numbers.
Stirling (1730): asymptotic approximation.
Ramanujan (1914): extraordinary series for factorials.
Trivia
- Number of digits of n!: log₁₀(n!) ≈ log₁₀(√(2πn)) + n·log₁₀(n/e)
- Trailing zeros of n!: = number of 5s in factorization = Σⁱₖ₌₁ ⌊n/5ᵏ⌋
- Example: 25! has 5+1 = 6 trailing zeros
FAQ
Why 0! = 1?
Convention. Empty product = 1 (neutral element). Enables elegant formulas: C(n,0) = 1. Consistent with Γ(1) = 1.
Why does n! explode?
Multiplies all positive integers up to n. 10! = 3.6M, 20! is 18 digits, 100! has 158 digits. Grows faster than any exponential.
How to calculate large n!?
(
- Exact with BigInt; (
- Stirling approximation (~1% error); (
- Gamma via Lanczos (15 digits). For n>170 use BigInt (double overflow)
Gamma function?
Extension to reals/complexes: Γ(n) = (n−1)! for positive integers. Γ(1/2) = √π. Poles at 0, −1, −2. Fundamental in statistics, physics.
Difference factorial vs double factorial?
n! all integers down to 1. n!! same-parity only. Ex: 5!=120, 5!!=15.
Use of derangements?
Permutations without fixed points. Hat problem, secret santa, file matching, cryptography.
Fast computation of n!?
Stirling: n! ≈ √(2πn)(n/e)ⁿ. For n=100: 9.32×10¹⁵⁷ (exact 9.33). ~0.08% error. Good enough for most non-financial apps.
Common errors
- 0! = 0 (FALSE, it's 1)
- Factorial of non-integers (only Gamma)
- Silent overflow beyond 170 (Infinity in JS)
- Confusing n!! with (n!)!
- Negative factorials (undefined, Gamma poles)
- Floating point for exact combinatorics
Updated July 2026
Comments (0)
Login to leave a comment.
No comments yet. Be the first!