**March cook-off 2018**

*Here is the link of my code. IT is not working, ALTHOUGH THE APPROACH LOOKS PROMISING.Please go through the code once*

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

**March cook-off 2018**

*Here is the link of my code. IT is not working, ALTHOUGH THE APPROACH LOOKS PROMISING.Please go through the code once*

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

2 Likes

Please add comments in your code or explain your approach in detail for faster and effective response.

Your code was hard to understand but I guess the problem lies potential over flow at

```
int sum = mid * (mid + 1) / 2;
if (sum <= s && (mid+1)*(mid+2) >=2*s)
return mid;
```

Ok there was one more mistake it should be â€śn+sumaâ€ť not â€śn+suma+1â€ť. Your AC submission.

I also misread the constraints and used binary search without generating array. You can refer to my solution, itâ€™s a bit cleaner than yours.

2 Likes

Remove â€ścommunity wikiâ€ť from your post or you wonâ€™t receive karma and so that next time you can create your own thread

Here is my approach for the problem ::

I used Quadratic formula to check the exact decimal value of n

Here x represents an unknown, while a, b, and c are constants with a not equal to 0. One can verify that the quadratic formula satisfies the quadratic equation by inserting the former into the latter. With the above parameterization, the quadratic formula is:

Now , I came up with this equation

if the value of n received after this is integer , weâ€™ll print the ans else weâ€™ll check for the absolute difference between this value and the closest possible upper and lower bound values , then print the one with lowest difference .

Hope it helps , rest in the solution

1 Like

thanks nilesh for your help.

Nilesh naam ke log coding me smart hote hai , it seems.

thanks harry potter . I tried this one but made mistake pointed by nilesh in the above comment.

ok man all the best in the upcoming contests