#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get_range(ll l, ll r) {
l--;
ll a = (l/ 9) * 45;
ll b = (r / 9) * 45;
for (int i = 1; i <= l % 9; i++) a += i;
for (int i = 1; i <= r % 9; i++) b += i;
return b - a;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
cout << get_range(l,r) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |