Python program to find factorial of a large number


Suppose we have a large number n. We have to find its factorial. In some other languages it is very hard to find factorial of a large number because it may exceed the range of integer data types. But in python it will automatically detect the length and also update the number into bigger integer format by default.

So, if the input is like n = 50, then the output will be

30414093201713378043612608166064768844377641568960512000000000000


To solve this, we will follow these steps −

  • import the factorial class from the math library

  • simply calculate factorial for n for any large value

Example

Let us see the following implementation to get better understanding

from math import factorial

def solve(n):
   return factorial(n)

n = 50
print(solve(n))

Input

50

Output

30414093201713378043612608166064768844377641568960512000000000000

Updated on: 12-Oct-2021

540 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements