StackOverflowError computing factorial of a BigInteger?
The problem here looks like its a stack overflow from too much recursion (5000 recursive calls looks like about the right number of calls to blow out a Java call stack) and not a limitation of BigInteger. Rewriting the factorial function iteratively should fix this. For example: public static BigInteger factorial(BigInteger n) { BigInteger result … Read more