Problem

My approach was that, a distinct sum is obtained only when adjacent elements in the range are added, say we have the range L=3, R=8 then, 3,4,5,6,7,8 the sum of 11 can be obtained by adding 5,6 or by adding 4,7 , or by adding 3,8… In my case, I’m trying to take only the pair containing adjacent elements i.e., 5,6… The other possible distinct sums are the sums obtained by taking the extreme elements twice in a pair i.e., (3,3) and (8,8)… So, the total number of pairs possible is, (number of pairs obtained from adjacent elements)+2 .i.e., (n-1)+2… My code implementing the same logic :

```
#include <iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc;
cin >> tc;
for(int t=0; t<tc; t++)
{
int l,r, res,n;
cin >> l >> r;
n = (r-l)+1;
res = n-1;
if(n == 1)
res += 1; //multiplying the boundary element with self
else
res += 2;
cout << res << endl;
}
return 0;
}
```

Can someone please explain what’s wrong with my approach…