#include <bits/stdc++.h>
using namespace std;
const bool cannot = 0;
int main(){
int q;
cin >> q;
while(q--){
long long l,r, templ, tempr, reml, remr, nons, ans = 0, rans, lans;
cin >> l >> r;
reml = l % 9;
remr = r % 9;
if(l <= 9 && r <= 9){
for(int i = l;i <= r;i++)
ans += i;
cout << ans << "\n";
continue;
}
else if(l <= 9){
lans = 45 - (l) * (l-1) / 2;
goto NEXT;
}
templ = (10 - ((reml == 0) * 9 + reml)) + l;
tempr = r - ((remr == 0) * 9 + remr - 1);
lans = 45 - (9 - (10 - ((reml == 0) * 9 + reml))) * (10 - (10 - ((reml == 0) * 9 + reml))) / 2;
nons = (tempr - templ + 1) / 9 * 45;
rans = (remr * remr + remr) / 2 - 1;
if(cannot){
NEXT : ;
tempr = r - ((remr == 0) * 9 + remr - 1);
nons = (tempr) / 9 - 1;
rans = (remr * remr + remr) / 2 - 1;
}
ans = nons + rans + lans + 1;
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |