Python program to find factorial of a large number

PythonServer Side ProgrammingProgramming

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
raja
Updated on 12-Oct-2021 09:00:24

Advertisements