I am getting TLE on last test case of this problem Link to the problem, i used Big mod Link to Big mod implmentation for multiplication while calculating power as we need last ten digits so we have to modulo it by 1e10 which will overflow in C++.
Any type of help is appreciated. Thanks in advance.
Auto comment: topic has been updated by Not-Afraid (previous revision, new revision, compare).
BigMod implementation adds another factor of $$$log (MOD)$$$, making the time complexity $$$O(n log n log MOD)$$$.To remove the $$$log (MOD)$$$ factor, You can compute the remainder modulo $$$2^{10}$$$ and $$$5^{10}$$$, and then find the remainder modulo $$$10^{10}$$$ using chinese remainder theorem.
can we do it without CRT ??
Thanks! I solved it using CRT. Solution
I found an implementation for Big mod in Discussion form of this question Ideone Link but couldn't understand what is it doing exactly, if you can help?