Sumwise

Factorial of 40

40! = 815915283247897734345611269596115894272000000000

48 digits

How it is calculated

40! = 40 × 39 × … × 2 × 1 = 8159152832478977343456112695961158942720…

Facts about 40!

Digits48
Trailing zeros9 (one for every factor 5 × 2)
Stirling estimate≈ 8.1422e+47
40! ÷ 39!40

Nearby factorials

38!523022617466601111760007… (45 digits)
39!203978820811974433586402… (47 digits)
41!334525266131638071081700… (50 digits)
42!140500611775287989854314… (52 digits)

What are factorials used for?

Counting arrangements: 40! is the number of different orders in which 40 distinct items can be lined up. Factorials also appear in probability, combinations and series.

Counting with 40!

There are 8.1591 × 10^47 different ways to arrange 40 different books on a shelf: 40 choices for the first place, 39 for the second, and so on down to one choice for the last. If you only fill the first three places, as with gold, silver and bronze among 40 runners, there are 40 × 39 × 38 = 59,280 possible podiums. If the order does not matter, divide by 3! = 6 to get 9,880 ways to choose a group of three. Choosing a pair from 40 people can be done in 780 ways.

In probability, if 40 names are drawn out of a hat one at a time, the chance of drawing them in one particular order is 1 in 8.1591 × 10^47. That is why shuffled decks and passwords with many symbols are so hard to guess.

How big is 40!?

40! has 48 digits, so it is beyond everyday counting: it dwarfs the number of grains of sand on Earth (around 10^18). The digits add up to 189, a multiple of 9, as they are for every factorial from 6! on. Stirling's formula, √(2πn) × (n/e)^n, gives a close estimate without multiplying everything out, and gets more accurate as n grows.

Prime factors of 40!

Every prime up to 40 divides 40!. Legendre's formula counts how often: add ⌊n/p⌋ + ⌊n/p²⌋ + ⌊n/p³⌋ + … for each prime p. For 40! that gives 2^38 × 3^18 × 5^9 × 7^5 × 11^3 × 13^3 × 17^2 × 19^2 × 23 × 29 × … (12 primes in all). The 9 trailing zeros come from pairing the 9 factors of 5 with factors of 2.

Shuffles where nothing stays put

A related count is the number of derangements of 40 items: orders in which no item ends up in its original place, as in a Secret Santa where nobody draws their own name. The count is the whole number nearest to 40! ÷ e, so about 36.8% of all 8.1591 × 10^47 orders are derangements. From about four items on, that share stays close to 1 ÷ e, roughly 37%, however many items there are.

Computing 40! yourself

In Excel or Google Sheets, type =FACT(40). Spreadsheets keep only 15 significant digits, so from 18! on the result is rounded, and FACT stops at 170!, the largest factorial that fits in a standard floating-point number. In Python, math.factorial(40) returns the exact integer with all 48 digits, because Python integers have no size limit. The gamma function extends factorials to fractions: Γ(n + 1) = n!, so (1/2)! = √π ÷ 2 ≈ 0.8862.

Why is 0! equal to 1?

There is exactly one way to arrange nothing, and the rule n! = n × (n − 1)! only works for n = 1 if 0! = 1. Defining it this way keeps formulas for combinations and series correct at the edges.

Calculate another factorial

How this answer was calculated

The result is worked out from the numbers in this page's address when the page is opened, using exact arithmetic wherever possible and rounding only for display. Nothing is copied from a printed table. If you think an answer is wrong, please tell us through the contact page and we will check it.

Reference this page

Copy a citation or link:

<a href="https://sumwisemath.com/calc/factorials/factorial-of-40/">Factorial of 40</a>
"Factorial of 40". Sumwise. https://sumwisemath.com/calc/factorials/factorial-of-40/

Questions

What is 40 factorial?

40! is the product of every whole number from 1 to 40.

How many digits does 40! have?

48. The number of digits of n! is the whole part of log10(n!) plus one.

How many zeros are at the end of 40!?

9. Count the factors of 5 in the numbers 1 to 40: there are always more factors of 2, so every 5 makes one trailing zero.

Is 40! divisible by 41?

No. 41 is prime and bigger than every factor of 40!, so it cannot divide it (Wilson's theorem says 40! leaves a remainder of 40 when divided by 41).

What is the last non-zero digit of 40!?

2. Strip the 9 trailing zeros and look at the digit that is left at the end.

What is 41! in terms of 40!?

41! = 41 × 40!. Each factorial is the previous one multiplied by the next whole number.