#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> pref;
ll suminc(ll x){
if (x==0){
return 0;
}
return pref[9]*(x/9)+pref[(x%9)];
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int q;
cin>>q;
pref.resize(10,0);
for (int i = 1; i<=9; i++){
pref[i]=pref[i-1]+i;
}
for (int i = 0; i<q; i++){
ll l,r;
cin>>l>>r;
cout<<(suminc(r)-suminc(l-1))<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
4 ms |
384 KB |
Output is correct |