#include <bits/stdc++.h>
#define in cin >>
#define out cout <<
#define endl '\n'
#define int long long
#define bismillah ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define v vector
#define pb push_back
using namespace std;
signed main () {
int q; in q;
int tmp = 45;
while (q--) {
int l,r; in l >> r;
int sz = r - l + 1;
int ans = 0;
if (l % 9 != 0) {
ans += ((9 - (l % 9) + 1) * ((l % 9) + 9))/2; sz -= (9 - (l % 9) + 1);
} else {
ans += 9; sz--;
}
if (sz == 0) goto here;
if (r % 9 != 0) {
ans += ((r % 9) * (1 + (r % 9)))/2; sz -= (r % 9);
} else {
ans += 1; sz--;
}
here:
sz /= 9;
ans += (sz * tmp);
out ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |