Small factorials Problem Code: FCTRL2

https://www.codechef.com/submit/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:
https://www.codechef.com/viewsolution/56201197

1 Like

Consider the test input:

1
13

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

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

1
100
1 Like

https://www.codechef.com/viewsolution/56203577
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.

[simon@simon-laptop][14:19:16]
[~/devel/hackerrank/otherpeoples]>echo "1
1" | ./a.out
1.000000

The expected answer is:

1

not

1.000000

Edit:

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

1
100

should be:

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

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: