Problem in CHMOD question !!

I have used precalculation technique . For ex. let 1 2 3 4 5 be array . Then through precomputation i have made another array . 1 2 6 24 120 . After that in order to cal any query it is :- arra[m]/arr[l-1] where l is lower rage and m is upper … Is my approach wrong… getting WA many times Could someone help me out. Solution is :-

Read the constraints again.


If all elements of the array are 100, the product of N such elements of the array will be:

100X100X100…100(N times)=(100)^N

This will quickly overflow for large values of N as maximum value of long long int is 10^18.
Therefore you need to implement multiplication between two numbers by adding their prime powers and then calculating (a^b)%c using fast squaring.

1 Like