#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
const int inf = INT_MAX;
const int mod = 1e9+7;
int f(int x){
while(x>=10){
int temp = 0;
while(x){
temp += x%10;
x/=10;
}
x = temp;
}
return x;
}
int32_t main(){
fast;
int pre[15] = {0};
for(int i=1;i<=10;i++){
pre[i] = pre[i-1] + i;
}
int t;
cin>>t;
while(t--){
int l, r;
cin>>l>>r;
int ans = 0;
int a = 0, b = 0;
a = f(l);
b = f(r);
ans += pre[9] - pre[a-1];
ans += pre[b];
l = l + 9-a;
r = r - b;
ans += (r-l)/9*pre[9];
cout<<ans<<endl;
}
}
//https://usaco.org/current/current/index.php?page=viewproblem2&cpid=282 bunu coz
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |