CodePudding user response:
You get signed integer overflow in sum = (r*(r 1))/2 - ((l-1)*l)/2;
.
Change the input parameters to your function to long int
s too:
int solve(long l, long r) {
You could also try replacing all your int
s and long
s with intmax_t
(you must #include <stdint.h>
first). If that's not enough, you must find an alternative way to solve the problem.