Small factorials Problem Code: FCTRL2
Please help me why I am unable to submit it. My output is exactly the same as asked. Still I am unable to submit.

Sorry I am new to this platform. This is the link:

1 Like

Consider the test input:


So should I use some other datatype like unsigned long int?

If you do, make sure it gives the correct output for:

1 Like
unsigned long int worked for 13! but not for 100!
So I tried double and answer came but still its showing wrong answer

The Online Judge for this problem seems to work (as is usually the case) by string comparison, meaning your output has to match the expected output exactly.

[~/devel/hackerrank/otherpeoples]>echo "1
1" | ./a.out

The expected answer is:





While I’m at it: the exact output for:


should be:


So we need to do typecasting. Right? But in which datatype beacuse as per my knowledge, double or long double has largest range. Correct me if I am wrong.
I tried using %.0Lf for long double or %0.lf for double to remove the decimal values and it worked. But then in 100!, its coming 93326215443944152668565874012822813729098311759684578422571477191227958488797196837776068881625682613838776673891747185651776997870022857465602436796780642304 and still some zeroes are missing at the end.
How to correct this and get the required output.

None of the built-in C types have sufficient range and precision to express 100!.

Have a search on the forums for this problem - there’s tons of threads on it :slight_smile: