Operations with factorial combination with a large index

I tried with BigIntegerfor operations with large numbers, but I see that the product operation is very slow when I calculate the combinations of CnR and factorials.

BigInteger n = BigInteger.ONE;
for (int i=1; i<=20; i++) {
    n = n.multiply(BigInteger.valueOf(i));
}

I am looking for a better algorithm, including ints arrays.

+3
source share
1 answer

Printing to the console is the slowest part of your code. Try not to print at each iteration. This will make your code much (!) Faster. The rest looks good. You can use primitive types, it will be a little faster than a real class, but not much.

+1
source

All Articles