Hi,

There was a contest held named Code Stumble and for one of the question I was unable to get an accepted solution and I can’t understand why. I compared some of the AC submitted code and tried random test cases on both of them and found out that all the answers are same. Can anyone help me as to where possibly I could have gone wrong.

Link to the question : https://www.codechef.com/COMB2018/problems/COMB1/

My logic for the question was that Sum of odd numbers from 1 to 2n is (n - 1)squared:

eg. 1 + 3 + 5 = 9 which is 3 squared. 1 + 3 + 5 + 7 = 16 which is 4 squared.

For a series not starting at 1 simply subrtact the smaller square : (1 + 3) + 5 + 7 = 16, Subtrating bracketed terms is 16 - 4 or 4^2 - 2^2 = 12. Generally: a…b odd integers, Sum is ((b+1) / 2)^2 - ((a-1) / 2)^2, both a and b included in sum.

Where a and b were calculated as a=2*l-1 and b=2*r-1

Link to my Solution : https://www.codechef.com/viewsolution/22501845

Thank you in Advance.