#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define db(x) cout << "[" << #x << "]: " << x << '\n';
int q, s, l, r;
int f(int n) {
if (n % 9 == 0) {
return 9;
}
return (n % 9);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> q;
while (q--) {
cin >> l >> r;
if (l + 100 >= r) {
s = 0;
for (int i = l; i <= r; ++i) {
s += f(i);
}
cout << s << '\n';
} else {
s = 0;
while (f(l) != 1) {
s += f(l);
++l;
}
while (f(r) != 9) {
s += f(r);
--r;
}
s += 45 * (r - l + 1) / 9;
cout << s << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |