Given an N x M matrix. The task is to repeat the following steps K! times.
- Add all the elements of the matrix and get a matrix sum (S) % mod 10^9 + 7
- Add S to all the elements. % mod 10^9 + 7
What I can think of regarding the complexity it will O(K! x N x M).
But K ranges from 1 to 10^5 and this is a huge number of iterations for a computer to process.
Is there a way to optimize these operations so that these can be performed using less computational resources.