I am given programming assignment, and I am asked to fit into time limit of test cases.
But because of this exponentiation, I don't see how.
Since exponentiation is an expensive operation, I want to do it less number of time.
Is there any simplification of this, so that I can do the same operation in less time?
$$\left(a_1^{a_2+a_3+a_4+a_5+\cdots+a_n}+ a_2^{a_1+a_3+a_4+\cdots+a_n)} +\cdots + a_n^{a_1+a_2+a_3+ \cdots +a_n-1} \right) \bmod K = \text{?}$$ $ 1\le a_i \le 4600, 1\le K \le 1200000, 100 \le n \le 3000$
What about evading exponentiation by taking log then it becomes the sum of the powers into the log and then you must antilog and add.
So each term will be the anti log of $ log((a1)^(a2 + ... +an)) = (a2+a3+...+) log(a1)$