GETTING WA IN FCTRL2

The program works on ideone and my computer by getting wrong answer here…pls help me in figuring this out…
http://www.codechef.com/viewsolution/3899163

The problem is that the range of int (any C/C++ data type) is limited and is at max 10^19. However factorial is a very fast growing function and is greater than 10^18 so it cannot be accomodated inside the data type. You will need to store the answer as string or arrays. Please refer to this tutorial by @kuruma for help.

@ishitach : your algorithm won’t work for n>=20. because answer cannot fit even in long long int. This question you should try using arrays. There is a small tutorial but very great one to solve this question using arrays. you can look at the tutorial link here

1 Like

You have declared your array to be holding integer type data but the range of integers, even the unsigned ones is limited to 65,535 and that would not suffice to hold the factorial of numbers even greater than 8. Also, the largest data type of C/C++ is not capable of holding values like that of 70!

If you want your code in the languages C/C++ then better approach would be to use this logic: Tutorial for Small Factorials | CodeChef

else if you know languages like Python and Java, they have in-built support(like Big Integer in Java) for holding such large values.

I have tried using BigIntegers…bt unable to resolve the errors as every integer is to b converted into BigInteger…
OI2ndM - Online Java Compiler & Debugging Tool - Ideone.com” here is my code