In this problem only one test case is being passed. All other test cases are not being passed.
Here is the code given below.
https://ide.codingblocks.com/s/111153
Problem in Broken Calculator
@ratulhans
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 negative answer due to overflow.
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 .
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.