80pts的逆天分数,#9#10TLE
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll A[11451419];
ll H[11451419];
ll i = 0;
ll work_out(ll x, ll y) {
ll t1 = lower_bound(A + 1, A + 1 + i, x) - A;
ll t2 = lower_bound(A + 1, A + 1 + i, y) - A;
x -= A[t1 - 1];
y -= A[t2 - 1];
if (t1 == t2) {
return H[y] - H[x - 1];
}
if (t1 == t2 - 1) {
return H[t1] - H[x - 1] + H[y];
}
ll sum = 0;
sum += H[t1] - H[x - 1];
sum += H[y];
t1++;
while (t1 < t2) {
sum += H[t1];
t1++;
}
return sum;
}
int main() {
ll T;
scanf("%lld", &T);
ll x, y;
while (A[i] <= 1000000000000) {
i++;
A[i] = i * (i + 1) / 2;
}
for (ll k = 1; k <= 1500000; k++) {
H[k] = H[k - 1] + k;
}
ll t;
while (T--) {
scanf("%lld", &x);
scanf("%lld", &y);
t = work_out(x, y);
printf("%lld\n", t);
}
return 0;
}