#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll L, R;
void solve() {
cin >> L >> R;
ll mi[9];
for (int i = 0; i < 9; i++) mi[i] = 2e18;
for (int i = 0; i < 10; i++) {
ll nVal = (L + i);
if (nVal > R) break;
mi[nVal % 9] = min(mi[nVal % 9], nVal);
}
ll sum = 0;
for (int i = 0; i < 9; i++) {
if (mi[i] == 2e18) continue;
//cerr<<i<<' '<<mi[i]<<'\n';
ll cnt = (R - mi[i]) / 9 + 1;
if (i == 0) sum += 9 * cnt;
else sum += i * cnt;
}
cout << sum << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T; cin >> T; while (T--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |