I simply used brute force to solve the problem.But my all test cases do not pass.I have tried this code for large numbers like 10^8,10^9,etc in online ide and my code gives right answer.Also,I havent optimized the for loops but still time complexity shouldn’t be the issue.(31 x 31 x 10^5).And if TLE is a problem,then judge should show TLE and not wrong answer.
Here is the link to my approach.
https://www.codechef.com/viewsolution/19972645
Please tell the failing test cases.Any help is highly appreciated.