题解:P10416 [蓝桥杯 2023 国 A] XYZ

· · 题解

题目理解:

AC 代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long l,r;
        cin>>l>>r;
        if(l*2>r){cout<<0<<endl;continue;}
        long long xl=l,xr=r-l;
        long long sum=(1+xr-xl+1)*(xr-xl+1)/2ll;
        cout<<sum<<endl;
    }
}

AC 记录