Please help, I am getting an TLE error. The time limit is very strict.
Problem link : http://www.spoj.com/problems/AP2/
Solution link : http://ideone.com/zwD4EJ
Solution is based on formula, so can't figure out how to optimize it.
Moreover, my solution which uses Long doesn't pass a testcase as suggested in comments. To pass it I would have to use Biginteger, and that would never be faster than the current solution which is already getting TLE.
Please suggest what to do.
Thanks.