Problem : https://www.codechef.com/LRNDSA05/problems/CHMOD

my solution : https://www.codechef.com/viewsolution/36597353

What I did in my code (please check, my logic is correct or not) -

we have array of n numbers :

let, array is :arr[] = [1 2 3 4 5] // (size = 5)

I declared a new array"mul" with size (n + 1) and take mul[0] = 1

then iterate through arr and update mul[i] with (mul[i - 1] * arr[i]) % M, which gives mul as -

mul = [1, 1, 2, 6, 24, 120] // here, M = 1e9

Here, mul[i] gives multiplication of array till ‘i’ mod M

Is this approach is correct? If correct then where it gives runtime error.