Broken Calculator

I am unable to find a mistake in my code…6 out of 7 test cases have been rejected. Please check my code. My code link is 159158.

@Kajal
Your code only works for small inputs till n<=20. Factorials grow extremely fast and go out of range of long long int even rather quickly.
If you try running your code for even input like n=21 or n=22 , you will see that it shows a wrong answer. Compare it with calculating the answer in your calculator.
This is actually less of a problem to calculate factorial as that part is extremely easy and more of a problem to find a way to store it . Even long long int datatype can only store a number atmost 18 digits long.
There is no data type in C++ to store such large numbers so you will need to figure out a way around this to store such large numbers and do the computations on it.
In this problem we can get an input as large as n=500 ( as specified in problem constraints ). 500! is over 1100 digits long.
Think of way to store such large values and try again.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.