List of utility methods to do BigInteger Factorial
BigInteger | factorial(BigInteger n) Naive (dumb) implementation of the factorial function. if (n.equals(BigInteger.ONE)) { return BigInteger.ONE; return n.multiply(factorial(n.subtract(BigInteger.ONE))); |
BigInteger | factorial(BigInteger n) Compute the Factorial of n, often written as c! in mathematics.
BigInteger nFac = BigInteger.ONE; while (n.compareTo(BigInteger.ONE) > 0) { nFac = nFac.multiply(n); n = n.subtract(BigInteger.ONE); return nFac; |
BigInteger | factorial(BigInteger number) factorial BigInteger result = BigInteger.valueOf(1); for (long factor = 2; factor <= number.longValue(); factor++) { result = result.multiply(BigInteger.valueOf(factor)); return result; |
BigInteger | factorial(BigInteger originValue) factorial BigInteger one = new BigInteger("1"); BigInteger result = new BigInteger("1"); while (originValue.compareTo(one) > 0) { result = result.multiply(originValue); originValue = originValue.subtract(one); return result; |