diff --git a/problem-solving/algorithms/implementation/extra-long-factorials/extra-long-factorials.java b/problem-solving/algorithms/implementation/extra-long-factorials/extra-long-factorials.java new file mode 100644 index 0000000..b6df21e --- /dev/null +++ b/problem-solving/algorithms/implementation/extra-long-factorials/extra-long-factorials.java @@ -0,0 +1,31 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.regex.*; + +public class Solution { + + // Complete the extraLongFactorials function below. + static void extraLongFactorials(int n) { + BigInteger factorial = new BigInteger("1"); + while (n > 1) { + factorial = factorial.multiply(BigInteger.valueOf(n)); + n--; + } + System.out.println(factorial); + } + + private static final Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + int n = scanner.nextInt(); + scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); + + extraLongFactorials(n); + + scanner.close(); + } +}