No Test Case Passed.Please tell why
Broken Calculator
Hello @siddharth_redhu you can do this in this way:
you have to use array for this :
the cinstraints are very high like:you cant store the result in any number even if you define the number as long long int because long long int can handle digits upto 1e18 only whereas accordinf to the constraints factorial of 500 is of length 158 digits
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.
I did not got how to use array.Please tell
Hey @siddharth_redhu you have reopened your doubt. you must be passing a single test case and failing rest. Reason for that is you will be having value of N in range of 1 to 500,
factorial of 100 is
100 ! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
No data type can store this much value as the logic you are using, won’t be applicable in solving this problem. So you have to think differently in this problem.
Think somewhat in this direction
A number 5189 is stored in res[] as following.
res[] = {9, 8, 1, 5}
x = 10
Initialize carry = 0;
i = 0, prod = res[0]*x + carry = 9*10 + 0 = 90.
res[0] = 0, carry = 9
i = 1, prod = res[1]*x + carry = 8*10 + 9 = 89
res[1] = 9, carry = 8
i = 2, prod = res[2]*x + carry = 1*10 + 8 = 18
res[2] = 8, carry = 1
i = 3, prod = res[3]*x + carry = 5*10 + 1 = 51
res[3] = 1, carry = 5
res[4] = carry = 5
res[] = {0, 9, 8, 1, 5}