FACTO SUM problem. one test case is failing

Hey ! you should take modulo at every step wherever you are updating your answer, even in step of calculating factorial because it may happen that one of the aray elements is 100 or larger for which you will not be able to calculate its factorial so you should take modulo at every iteration.

Thanks,it worked. but why modulo at every step??

suppose you have to calculate the factoiral of 100 then you know it has 158 digits so we can’t store this in long long int So what we do is 100!%(10^9+7). this means we are taking modulo of 100 factorial with 10^9+7 so 100! is nothing but product of consecutive natural nos upto 100 , using modulo property (ab)%M=(a%Mb%M)%M, you can find the value of ans %M

1 Like