In SPOJ, there is a problem to find factorial for numbers between 1 and 100. Though the algorithm for the problem is very easy and simple, finding the right datatype to handle the factorial of larger numbers was not so easy. But the solution is however made simple by java.math.Integer
Amazing thing about BigInteger, the number of digits that it can hold is limited by the memory of the system. It would be unfair to the rest of people who are trying to find the solution if I post the solution here but I can sure help others and save the time I spent researching on this problem.
Follow this sample program: http://leepoint.net/notes-java/data/numbers/60factorial.html
No comments:
Post a Comment