#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
// 1-9=45
// 1-18=90
ll l,r;
ll solve(ll n){
ll count,x,idx,sum=0;
idx=n%9+1;
while(idx--)sum+=idx;
count=n/9;
x= 45*count+sum;
return x;
}
int main(){
ios
ll t; cin >> t;
while (t--){
cin >> l >> r;
cout << solve(r)-solve(l-1) << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |