We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

withouth trying the code, I notice that you are using "long" vars, the problem mention that some of the number cannot be stored in a long (ie 64 bit type).
Probably with a BigInteger can work.

it only works with n=1,2,....,19. The statement asks you to calculate 0<=n<=100. with a big n the answer of your code is negative because it overflows.

## Extra Long Factorials

You are viewing a single comment's thread. Return to all comments →

hello, I use java and try to solve it using a recursive method

the result is not correct, but I can't find the reason. Please help.

withouth trying the code, I notice that you are using "long" vars, the problem mention that some of the number cannot be stored in a long (ie 64 bit type). Probably with a BigInteger can work.

Yes,you are right! Thank you!

Obviously it's a recursive solution, but the problem is much bigger than it. You have to calculate factorial using manually implemented data types.

it only works with n=1,2,....,19. The statement asks you to calculate 0<=n<=100. with a big n the answer of your code is negative because it overflows.