Editorial for An Exponentiation Problem
Submitting an official solution before solving the problem yourself is a bannable offence.
There were multiple ways to solve this.
In Java or Python, there exists a standard library method that we could use to solve this exact problem.
In Python, this is:
pow(base, exponent, modulo)
In Java, this is:
If you are not using the aforementioned languages, such as C/C++, you needed to code a power function. However, notice that , meaning that simply multiplying times is too slow, and will TLE. We can use a method called Exponentiation by squaring to reduce the time complexity to a sub-linear one instead of a linear one.