#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int sum_of_digits(ll x) {
if (x/10 == 0) return x;
ll temp = 0;
while (x > 0) {
temp += x%10;
x /= 10;
}
return sum_of_digits(temp);
}
int main() {
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = 0;
ll tot = r-l;
ll cnt = tot/10;
ans += 1ll*45*cnt;
ll start = sum_of_digits(l);
ll end = sum_of_digits(r);
if (end < start) {
while (start <= 9) {
ans += start;
start++;
}
while (end >= 1) {
ans += end;
end--;
}
}
else {
while (start <= end) {
ans += start;
start++;
}
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |