![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements