Factorial Formula - GeeksforGeeks (2024)

Last Updated : 10 Oct, 2024

Summarize

Comments

Improve

Factorial of a number ‘n’ is defined as the product of all the whole numbers less than ‘n’ up to 1. So, it can be defined as a factorial for a number 4 as 4 × 3 × 2 × 1 = 24. It is represented by the symbol ‘!’.

Factorial Formula - GeeksforGeeks (1)

Factorial Formula

Factorial of n = n! = n × (n – 1) × (n – 2) × … × 1

Examples:
0! = 1
1! = 1
3! = 3 x 2 x 1 = 6
4! = 4 x 3 x 2 x 1 = 24

Properties of Factorial

  • A factorial of any number is a whole number
  • A factorial can also be represented as a recursive function.

n! = n × (n – 1) × (n – 2) × … × 1 = n × (n – 1)!

  • Factorial of zero is 1, that is 0! = 1
  • Factorial of negative numbers is not defined

Uses of the factorial formula

The factorial formula is used in many areas, specifically in permutations and combinations of mathematics. For example,

  • The number of ways n distinct objects can be arranged in a row is equal to n!
  • Permutation gives the number of ways to select r elements from n elements when order matters. It is given using the formula nPr.

nPr = n! / (n – r)!

  • Combination gives the number of ways to select r elements from n elements where order does not matter. It is given as nCr.

nCr = n! / r! (n – r)!

Formula for Counting Trailing 0s in Factorial

Trailing 0s in n! = Count of 5s in prime factors of n! = floor(n/5) + floor(n/25) + floor(n/125) + … + 0

How does this work? A 0 is formed by multiplication of 5 and 2. So if we consider all prime factors of all numbers from 1 to n, there would be more 2s than 5s. So the number of 0s is limited by number of 5s. If we count number of 5s in prime factors, we get the result. Consider the following examples:

n = 5: There is one 5 and three 2s in prime factors of 5! (2 * 2 * 2 * 3 * 5). So a count of trailing 0s is min(1, 3) = 1.
n = 11: There are two 5s and eight 2s in prime factors of 11! (2 8 * 34 * 52 * 7). So the count of trailing 0s is min(2, 8) = 2.

We can observe that the number of 2s in prime factors is always more than or equal to the number of 5s. So, if we count 5s in prime factors, we are done.

Sample Problems

Question 1: Find the value of factorial of 5.

Solution:

To find the factorial of 5, we need to multiply all the whole numbers smaller than or equal to 5.

5! = 5 × 4 × 3 × 2 × 1 = 120

Hence, 5! = 120

Question 2: Find the value of a number x, given factorial of x, is 720.

Solution:

Apply the recursive property of factorial to find x. Until and unless we get 720 as our result, we will proceed recursively.

1! = 1

2! = 2 × 1! = 2

3! = 3 × 2! =6

4! = 4 × 3! = 4 × 6 = 24

5! = 5 × 4! = 5 × 24 = 120

6! = 6 × 5! = 6 × 120 = 720

Since 720 is obtained as the factorial of 6, one can compare the value of x with 6.

Thus, the value of x = 6

Question 3: Find the number of ways 5 distinct objects can be arranged in a row.

Solution:

Use the property that the number of ways n distinct objects can be arranged in a row is equal to n!

Thus, 5 distinct objects can be arranged in 5! = 5 × 4 × 3 × 2 × 1 = 120.

So, the number of ways is equal to 120.

Question 4: Find the number of ways 3 students can be selected from a class of 50 students.

Solution:

To find the number of ways 3 students can be selected from a class of 50 students, we can use the formula for Combination, since the order of the selected three students does not matter here.

Thus, the total number of ways = 50C3

So, this can be simplified as 50C3 = 50! / (3! × 47!) = (50 × 49 × 48 × 47!) / (3! × 47!) = 50 ×49 × 48 / 6 = 19,600

So, there are a total of 19,600 ways.

Question 5: Three different fruits are to be distributed among a group of 10 people. Find the total number of ways this can be possible.

Solution:

Since, in this case, the order of how the fruits are distributed matters, we need to implement Permutation.

So, the total number of ways is given as 10P3.

Simplifying, this can be written as,

10P3 = 10! / (10 – 3) ! = 10! / 7! = 10 × 9 × 8 × 7! / 7! = 10 × 9 × 8 = 720

Thus, there are a total of 720 ways possible.

Practice Problems on Factorial Formula

  1. Find the value of 7!.
  2. Determine the value of x if the factorial of x is 5040.
  3. How many ways can 6 distinct objects be arranged in a row?
  4. Calculate the number of ways 4 students can be selected from a class of 30 students.
  5. Find the number of permutations of the word “MATH”.
  6. How many different ways can 3 identical red balls and 2 identical blue balls be arranged in a row?
  7. In how many ways can a committee of 4 members be chosen from a group of 12 people?
  8. A password consists of 3 distinct letters chosen from the alphabet. How many possible passwords can be formed?
  9. Calculate the number of ways to arrange the letters in the word “COMPUTER” such that the vowels always come together.
  10. How many ways can 5 people be seated in a row if two specific people must sit next to each other?

Conclusion

The factorial is a very strong number agent as it helps to find out the product of all positive integers until a certain point represented by n!. It acts as a base for permutations and combinations, so it plays an important part in providing the number of ways to arrange or choose. It is important that one understands both its characteristics and applications when trying to solve different kinds of combinatorial problems in math.

FAQs on Factorial Formula

What is the factorial of a number?

The factorial of a number n (denotes an n!) is the product of all positive integers less than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120

What is the factorial of zero?

The factorial of zero (0!) is defined as 1. This is a special case and is used in many mathematical formulas.

Why is the factorial of negative numbers undefined?

Factorials are defined only for non-negative integers because they represent the product of a sequence of decreasing positive integers. There is no sequence of positive integers to multiply when the number is negative, making the factorial undefined for negative numbers.

How are factorials used in permutations and combinations?

In permutations, the factorial formula is used to calculate the number of ways to arrange n distinct objects in a specific order. In combinations, it is used to determine the number of ways to choose r objects from n objects without regard to order.

Can factorials be used in recursive functions?

Yes, factorials can be represented and calculated using a recursive function. The recursive definition is n! = n x (n-1)! with the base case being 0! = 1.



S

souvikm02

Factorial Formula - GeeksforGeeks (2)

Improve

Previous Article

Exponential Decay Formula

Next Article

Combinations Formula with Examples

Factorial Formula - GeeksforGeeks (2024)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Catherine Tremblay

Last Updated:

Views: 6668

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.