#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pll pair<long long, long long>
#define ppl pair<pll, long long>
#define ll long long
#define se second
#define fi first
#define pb push_back
ll T,n,nq,a[1001009],m,p,cyc,cmp,k,b[1001009],bn,r,res,y,vis1[4000009],vis[4000009],x,ma[400009],l;
string s,s1[9],t;
vector<ll>re;
vector<ll>g[100009],cc[100009];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("paintbarn.in", "r", stdin);
//freopen("paintbarn.out", "w", stdout);
//freopen("cereal.in", "r", stdin);
//freopen("cereal.out", "w", stdout);
cin>>T;
while(T--)
{
cin>>l>>r;
res=0;
res+=(r-l+1)/9;
res*=45;
if((l-1)/9==(r-1)/9)
{
ll l1=l%9;
if(!l1)l1=9;
ll r1=r%9;
if(!r1)r1=9;
res+=(r1+l1)*(r1-l1+1)/2;
}
else
{
x=r%9;
if(!x)x=9;
res+=(1+x)*(x)/2;
x=9-l%9;
if(!(l%9))x=9;
res+=(x+9)*(9-x+1)/2;
}
cout<<res<<endl;
}
//for(int i=1;i<=n;i++)cout<<a[i]<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |