We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ee34336 commit 1ddd661Copy full SHA for 1ddd661
src/main/java/com/thealgorithms/maths/Factorial.java
@@ -1,5 +1,7 @@
1
package com.thealgorithms.maths;
2
3
+import java.math.BigInteger;
4
+
5
public final class Factorial {
6
private Factorial() {
7
}
@@ -10,13 +12,13 @@ private Factorial() {
10
12
* @param n the number
11
13
* @return the factorial of {@code n}
14
*/
- public static long factorial(int n) {
15
+ public static BigInteger factorial(int n) {
16
if (n < 0) {
17
throw new IllegalArgumentException("Input number cannot be negative");
18
- long factorial = 1;
19
+ BigInteger factorial = BigInteger.ONE;
20
for (int i = 1; i <= n; ++i) {
- factorial *= i;
21
+ factorial = factorial.multiply(BigInteger.valueOf(i));
22
23
return factorial;
24
0 commit comments