The factorial of a number is defined as the product of all natural numbers up to that number. For example, factorial of 5 or ** 5!** is

**=**

*1 x 2 x 3 x 4 x 5***.**

*120*Extra long factorials are factorials of numbers greater than 20. They can be very big with an order of magnitude greater than ** 2^64** which can not be stored even in long long data types in C or C++. Modern languages like Python and JavaScript can easily store them.

## Python Code for Extra Long Factorials Hackerrank Solution

```
def extraLongFactorials(n):
# Write your code here
fact = 1
for num in range(2, n+1):
fact *= num
print(fact)
if __name__ == '__main__':
n = int(input().strip())
extraLongFactorials(n)
```

### Input

25

### Output

15511210043330985984000000

## JS Code for Extra Long Factorials Hackerrank Solution

Javascript output large numbers in scientific notation. We will get the output of 25! as 1.5511210043330984e+25. To avoid this we have to use BigInt.

```
function extraLongFactorials(n) {
// Write your code here
var fact = BigInt(1)
for(var num=2n; num<=n; num++){
fact = fact * num
}
console.log(fact.toString())
}
function main() {
const n = parseInt(readLine().trim(), 10);
extraLongFactorials(n);
}
```

### Output

15511210043330985984000000

### HackerRank Snapshot

**Also Read:**

- Item Price Generator Hackerrank Solution
- Insertion Sort Part 2 Hackerrank Solution in C
- Extra Long Factorials Hackerrank Solution
- Java Datatypes Hackerrank Solution
- Smart Number Hackerrank Solution
- Python Average Function Hackerrank Solution
- Company Logo Hackerrank Solution
- Matrix Summation Hackerrank Solution
- A company is repainting its office – HackerRank Solution
- Maximum Product Subarray in O(N) Time – Leetcode Solution
- Minimum number of transformation steps required to make all elements of an array equal
- NxNxN Matrix in Python 3
- Boruvka’s Algorithm in Python
- Roti Prata SPOJ Problem Solution – Complete Solution Approach with C++ and Java Code
- Lee Algorithm in Python | Solution to Maze Routing Problem in Python
- Vending Machine with Python Code
- Top 20 Array Coding Questions for Online Assessment
- Heap Sort Algorithm in Python
- Heap Sort Algorithm|Heap Data Structure
- Insertion Sort Algorithm in Data Structures using Python
- Quick Sort algorithm in data structures and algorithms using Python
- Selection Sort Algorithm In Data Structures and Algorithms using Python
- Searching Algorithms: Linear Search Algorithm
- Bubble Sort Algorithm In Data Structures & Algorithms using Python
- Merge Sort Algorithm in Python
- Binary Search in python
- Linear Search Python
- Sorting Algorithms and Searching Algorithms in Python
- Binary Search In Python
- Adding three matrices