 # Same logic but different result in CHFING problem of july long challenge

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.

I also did using making cases. My logic was
First number (A) = K - 1
Difference between consecutive terms (D) = N - 1
Last term (L) = A % D
No. of terms (T) = ((A - L)*T) / 2
Ans should be = ((A + L) * T) / 2

Cases were:
If T is even divide T by 2 and then multiply (A + L) with it.
Else divide (A + L) by 2 then multiply T with it.

There is no need of using double as we know among (A + L) and T at least one will be even number.

I used the exact same odd-even logic and I got the answer pretty quickly. Check out my answer, it’s written using very easy variables and easy to understand code.

https://www.codechef.com/viewsolution/24790923