# Small factorials Problem Code: FCTRL2

**URL:** <https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109>\
**Category:** help\
**Tags:** help, c, c-plus-plus, debugging\
**Created:** [January 10, 2022, 1:22pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109 "2022-01-10T13:22:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamriya](https://discuss.codechef.com/user_avatar/discuss.codechef.com/iamriya/32/24644_2.png) [@iamriya](https://discuss.codechef.com/u/iamriya)\
**Post date:** [January 10, 2022, 1:22pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/1 "2022-01-10T13:22:38Z")

</div>

> **[CodeChef: Practical coding for everyone](https://www.codechef.com/submit/FCTRL2)**
>
> Learn to code for free using our beginner friendly and interactive learning courses. Get all the practical skills required to excel at computer science. Start learning with CodeChef today and unlock your potential as a developer!

Please help me why I am unable to submit it. My output is exactly the same as asked. Still I am unable to submit.

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [January 10, 2022, 1:25pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/2 "2022-01-10T13:25:06Z")

</div>

> [@iamriya](#):
>
> [CodeChef: Practical coding for everyone](https://www.codechef.com/submit/FCTRL2)

> [@https://www.codechef.com/submit/BGL1215](https://discuss.codechef.com/t/https-www-codechef-com-submit-bgl1215/87555/4):
>
> This is how you link to a submission: [https://www.codechef.com/viewsolution/44519998](https://www.codechef.com/viewsolution/44519998) Linking to https://www.codechef.com/submit/\<problemname\> won’t work, as there is nothing in that URL that uniquely identifies a user, nor a specific submission.

---

<div class="post-metadata">

**Author:** ![iamriya](https://discuss.codechef.com/user_avatar/discuss.codechef.com/iamriya/32/24644_2.png) [@iamriya](https://discuss.codechef.com/u/iamriya)\
**Post date:** [January 10, 2022, 1:28pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/3 "2022-01-10T13:28:13Z")

</div>

Sorry I am new to this platform. This is the link:  
[https://www.codechef.com/viewsolution/56201197](https://www.codechef.com/viewsolution/56201197)

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [January 10, 2022, 1:31pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/4 "2022-01-10T13:31:07Z")

</div>

Consider the test input:

```auto
1
13

```

---

<div class="post-metadata">

**Author:** ![iamriya](https://discuss.codechef.com/user_avatar/discuss.codechef.com/iamriya/32/24644_2.png) [@iamriya](https://discuss.codechef.com/u/iamriya)\
**Post date:** [January 10, 2022, 1:36pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/5 "2022-01-10T13:36:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [January 10, 2022, 1:36pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/6 "2022-01-10T13:36:57Z")

</div>

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

```auto
1
100

```

---

<div class="post-metadata">

**Author:** ![iamriya](https://discuss.codechef.com/user_avatar/discuss.codechef.com/iamriya/32/24644_2.png) [@iamriya](https://discuss.codechef.com/u/iamriya)\
**Post date:** [January 10, 2022, 2:18pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/7 "2022-01-10T14:18:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [January 10, 2022, 2:20pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/8 "2022-01-10T14:20:58Z")

</div>

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_.

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

```

The expected answer is:

```auto
1

```

not

```auto
1.000000

```

**Edit:**

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

```auto
1
100

```

should be:

```auto
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

```

---

<div class="post-metadata">

**Author:** ![iamriya](https://discuss.codechef.com/user_avatar/discuss.codechef.com/iamriya/32/24644_2.png) [@iamriya](https://discuss.codechef.com/u/iamriya)\
**Post date:** [January 10, 2022, 3:06pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/9 "2022-01-10T15:06:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [January 10, 2022, 3:08pm UTC](https://discuss.codechef.com/t/small-factorials-problem-code-fctrl2/98109/10 "2022-01-10T15:08:13Z")

</div>

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 🙂
