MTRICK - TLE (python)

Here’s the link to my solution : http://www.codechef.com/viewsolution/3243656
i saw some accepted solutions which were the same except that they used O(n^2) techniques for reversing.
I can’t get why I am getting a TLE when my solution works much better . Any help appreciated :slight_smile:

If I were you, I would do

x=(x*r[1])%r[2]
y=(y*r[1])%r[2]
1 Like

I was getting a TLE, not a WA; but with your improvement, it got accepted. Can you explain the reason? If my original approach was wrong, I should have gotten a WA!

In python the number size is not limited, right? So for test case MMMM…MMMM and multiplying by let say 1018 everytime, you will have really big number and my tip was that calculation with such a big number is slow… Same problem is in Java when using BigInteger…

Thanks for the help !