The problem is https://www.codechef.com/JUNE19B/problems/CHFING

I used Arithmetic progression formula in my both solutions https://www.codechef.com/viewsolution/24694462 https://www.codechef.com/viewsolution/24657906

In https://www.codechef.com/viewsolution/24657906 i did not used inverse modulo and hence divided the problem into two cases (depending on number of terms in arithmetic progression is odd or even).I think may be due to large number of operations some miscalculation happens as a corner case .But logic is right and it is failing only one test case .can someone figure out the mistake ?

In https://www.codechef.com/viewsolution/24694462 i solved the problem directly (without making cases by using inverse modulo).All test cases got passed.