Give me effieient solution for this problem all acse are not working

100! produces very large no that we can not store in long long also

Hey @aryanraj since 100! can be a very large number we will store it in an array, i.e we will make an array of size MAX where MAX is the number of maximum digits in the output and this array would contain each digit, for example if the number is 123 then arr[0] =3, arr[1] =2, arr[2] = 1. Now we have an array consisting of number and we have to multiply that number with say x then we will follow these steps.

  1. Initialize carry as 0.
  2. Find value of res[i] * x + carry. Let this value be prod.
  3. Update res[i] by storing last digit of prod in it.
  4. Update carry by storing remaining digits in carrying.
    here res is the array consisting of your number and x is the number with which we want to multiply and we will do this for i = 0 to res_size -1.
    Now we know how to multiply we just need to intialize res with 1 and then multiply it with 1, 2, 3… n to get answer.

Here is code for calculating factorial of n, using the same algorithm described above.
This code is only for reference purpose, I strongly encourage you to write your own code.

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.