#include <bits/stdc++.h>
#define int long long
#define bismillah ios_base::sync_with_stdio(false);
using namespace std;
int digital_root(int x){
return x == 0 ? 0 : (x - 1) % 9 + 1;
}
signed main(){
bismillah;
int q;
cin >> q;
while(q--){
long long L, R;
cin >> L >> R;
long long len = R - L + 1;
int start = digital_root(L);
long long total = 0;
long long full = len / 9;
total += full * 45;
long long rem = len % 9;
for(int i = 0; i < rem; i++){
total += (start + i - 1) % 9 + 1;
}
cout << total << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |