{
  "id": "factorial",
  "version": "8d6e55a03f53",
  "status": "published",
  "name": "Factorial Calculator",
  "question": "What is the factorial of n?",
  "summary": "Computes n! exactly for any whole number from 0 to 1,000, with the number of digits, the trailing zeros and the value in scientific notation.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/factorial-calculator",
  "markdown": "https://www.acalculator.org/math/factorial-calculator.md",
  "kind": "function",
  "method": "n! = n × (n − 1) × … × 2 × 1, with 0! = 1; trailing zeros ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ….",
  "assumptions": [
    "n is a whole number from 0 to 1,000.",
    "n! is exact (every digit); the scientific form is rounded half up to 6 significant digits."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "n": {
        "title": "n",
        "description": "A whole number from 0 to 1,000.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000
      }
    }
  },
  "outputs": {
    "factorial": {
      "label": "n!",
      "description": "n × (n − 1) × … × 2 × 1, exactly; 0! = 1.",
      "format": "integer"
    },
    "approx": {
      "label": "In scientific notation",
      "description": "n! to 6 significant digits, shown when it has more than 15 digits.",
      "format": "text"
    },
    "digits": {
      "label": "Digits",
      "description": "How many digits n! has.",
      "format": "integer"
    },
    "zeros": {
      "label": "Trailing zeros",
      "description": "How many zeros n! ends with: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ….",
      "format": "integer"
    },
    "product": {
      "label": "Product",
      "description": "The factors multiplied, from n down to 1.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "n": 10
    },
    "outputs": {
      "factorial": "3628800",
      "digits": 7,
      "zeros": 2,
      "product": "10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1"
    },
    "text": "10! = 3,628,800."
  },
  "examples": [
    {
      "given": {
        "n": 5
      },
      "expect": {
        "factorial": 120,
        "digits": 3,
        "zeros": 1,
        "product": "5 × 4 × 3 × 2 × 1"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §13.1 Sequences and Their Notations (0! = 1, 1! = 1, n! = n(n − 1)(n − 2)⋯(2)(1) for n ≥ 2; 4! = 24, 5! = 120, 7! = 5,040), https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-1-sequences-and-their-notations (retrieved 2026-10-02); Python 3: math.factorial(5)"
    },
    {
      "given": {
        "n": 0
      },
      "expect": {
        "factorial": 1,
        "digits": 1,
        "zeros": 0
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §13.1 Sequences and Their Notations (0! = 1, 1! = 1, n! = n(n − 1)(n − 2)⋯(2)(1) for n ≥ 2; 4! = 24, 5! = 120, 7! = 5,040), https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-1-sequences-and-their-notations (retrieved 2026-10-02)"
    },
    {
      "given": {
        "n": 9
      },
      "expect": {
        "factorial": 362880,
        "zeros": 1
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §13.5 Counting Principles (9! = 362,880), https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-5-counting-principles (retrieved 2026-10-02); Python 3: math.factorial(9)"
    },
    {
      "given": {
        "n": 25
      },
      "expect": {
        "approx": "1.55112 × 10²⁵",
        "digits": 26,
        "zeros": 6,
        "product": "25 × 24 × 23 × … × 2 × 1"
      },
      "source": "hand calculation in content.mdx: ⌊25/5⌋ + ⌊25/25⌋ = 6 zeros; Python 3: math.factorial(25) = 15511210043330985984000000; OpenStax, Algebra and Trigonometry 2e, §13.1 Sequences and Their Notations (0! = 1, 1! = 1, n! = n(n − 1)(n − 2)⋯(2)(1) for n ≥ 2; 4! = 24, 5! = 120, 7! = 5,040), https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-1-sequences-and-their-notations (retrieved 2026-10-02)"
    },
    {
      "given": {
        "n": 100
      },
      "expect": {
        "approx": "9.33262 × 10¹⁵⁷",
        "digits": 158,
        "zeros": 24
      },
      "source": "hand calculation in content.mdx: ⌊100/5⌋ + ⌊100/25⌋ = 24 zeros; Python 3: len(str(math.factorial(100))) = 158; OpenStax, Algebra and Trigonometry 2e, §13.1 Sequences and Their Notations (0! = 1, 1! = 1, n! = n(n − 1)(n − 2)⋯(2)(1) for n ≥ 2; 4! = 24, 5! = 120, 7! = 5,040), https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-1-sequences-and-their-notations (retrieved 2026-10-02)"
    }
  ],
  "sources": [
    "OpenStax, Algebra and Trigonometry 2e, §13.1 Sequences and Their Notations (0! = 1, 1! = 1, n! = n(n − 1)(n − 2)⋯(2)(1) for n ≥ 2; 4! = 24, 5! = 120, 7! = 5,040). https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-1-sequences-and-their-notations (retrieved 2026-10-02)",
    "OpenStax, Algebra and Trigonometry 2e, §13.5 Counting Principles (9! = 362,880 orders; factorials in permutations). https://openstax.org/books/algebra-and-trigonometry-2e/pages/13-5-counting-principles (retrieved 2026-10-02)"
  ],
  "related": [
    "permutation",
    "combination"
  ],
  "changelog": []
}
