Find the Bug in the logic

http://www.codechef.com/viewsolution/3659313
My code was able to pass all test cases except one…i used the sum=k/2(2*a+(k-1)*d) logic to find first term … can u tell me why this logic has failed?(see the submissions…)