JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Calculate factorial of very large number even larger than long
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
import java.io.BufferedReader;
public class Program {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
final int n = Integer.parseInt(br.readLine());
System.out.println(factorial(n));
}
private static BigInteger factorial(int n){
BigInteger result = BigInteger.ONE;
for(int i =2;i<=n;i++)
result =result.multiply(BigInteger.valueOf(i));
return result;
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run