#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
int sembilan[] = {9, 1, 2, 3, 4, 5, 6, 7, 8};
int q;
ll l, r;
int toDigit(ll i) {
return sembilan[i%9];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
cin >> q;
while(q--) {
cin >> l >> r;
ll ans = 0;
ans += ((r-l)/9)*45;
r = ((r-l)%9)+l;
for(ll i = l;i <= r; i++) {
ans += toDigit(i);
}
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |